add utils file and start implementation of links

This commit is contained in:
Erik Edrosa 2015-12-25 21:46:37 -05:00
parent 8ac826f08c
commit 5cfa9166e6
4 changed files with 47 additions and 0 deletions

View File

@ -4,6 +4,7 @@ moddir=$(prefix)/share/guile/site/2.0
godir=$(prefix)/share/guile/site/2.0
SOURCES = \
commonmark/utils.scm \
commonmark/node.scm \
commonmark/blocks.scm \
commonmark/inlines.scm \

View File

@ -19,6 +19,7 @@
#:use-module (ice-9 regex)
#:use-module (ice-9 rdelim)
#:use-module (commonmark node)
#:use-module (commonmark utils)
#:export (parse-blocks))
;; String -> String
@ -251,6 +252,16 @@
(define (make-paragraph line)
(make-paragraph-node line))
(define (parse-reference-definition n col)
(cond ((not (node? n)) (col n '()))
((paragraph-node? n) (col n '(p)))
(else (map&co parse-reference-definition (node-children n)
(lambda (v d)
(col (make-node (node-type n)
(node-data n)
v)
d))))))
;; Line is one of:
;; - String

View File

@ -20,6 +20,7 @@
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-26)
#:export (make-node
node?
node-type
node-children
node-data

34
commonmark/utils.scm Normal file
View File

@ -0,0 +1,34 @@
;; Copyright (C) 2015 Erik Edrosa <erik.edrosa@gmail.com>
;;
;; This file is part of guile-commonmark
;;
;; guile-commonmark is free software: you can redistribute it and/or
;; modify it under the terms of the GNU Lesser General Public License
;; as published by the Free Software Foundation, either version 3 of
;; the License, or (at your option) any later version.
;;
;; guile-commonmark is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU Lesser General Public License for more details.
;;
;; You should have received a copy of the GNU Lesser General Public License
;; along with guile-commonmark. If not, see <http://www.gnu.org/licenses/>.
(define-module (commonmark utils)
#:export (map&co))
;; f: (a k' -> d)
;; k': b (listof c) -> d
;; l: (listof a)
;; k: (listof b) (listof c) -> d
;; f l k -> d
(define (map&co f l k)
"like map but uses a continuation to collect an extra list of values"
(if (null? l)
(k '() '())
(f (car l) (lambda (v d)
(map&co f (cdr l)
(lambda (v2 d2)
(k (cons v v2) (append d d2))))))))