diff options
Diffstat (limited to 'src/emit.scm')
-rw-r--r-- | src/emit.scm | 69 |
1 files changed, 34 insertions, 35 deletions
diff --git a/src/emit.scm b/src/emit.scm index e57e437..4c3581f 100644 --- a/src/emit.scm +++ b/src/emit.scm | |||
@@ -1,3 +1,5 @@ | |||
1 | (declare (module (jimmy emit))) | ||
2 | |||
1 | (import scheme (chicken base) | 3 | (import scheme (chicken base) |
2 | (chicken format) | 4 | (chicken format) |
3 | (chicken irregex) | 5 | (chicken irregex) |
@@ -9,41 +11,36 @@ | |||
9 | (for-each display (map format-stanza doc))) | 11 | (for-each display (map format-stanza doc))) |
10 | 12 | ||
11 | (define-public formats | 13 | (define-public formats |
12 | ;;; (TYPE (line . LINE-FMT) (stanza . STANZA-FMT) (inline . INLINE-FMT)) | 14 | (make-parameter |
13 | '((para (line . "~A") | 15 | ;; (TYPE (line . LINE-FMT) (stanza . STANZA-FMT) (inline . INLINE-FMT)) |
14 | (stanza . "~A~%~%")) | 16 | '((para (line . "~A") |
15 | (verb (line . "~A~%") | 17 | (stanza . "~A~%~%")) |
16 | (stanza . "```~%~A```~%~%")) | 18 | (verb (line . "~A~%") |
17 | (link (line . "=> ~A ~A~%") ; Note: link has 2 format arguments | 19 | (stanza . "```~%~A```~%~%")) |
18 | (stanza . "~A~%") | 20 | (link (line . "=> ~A ~A~%") ; Note: link has 2 format arguments |
19 | (inline . "~%=> ~A ~A~%")) | 21 | (stanza . "~A~%") |
20 | (list (line . "* ~A~%") | 22 | (inline . "~%=> ~A ~A~%")) |
21 | (stanza . "~A~%")) | 23 | (list (line . "* ~A~%") |
22 | (quot (line . "~A") | 24 | (stanza . "~A~%")) |
23 | (stanza . "> ~A~%~%")) | 25 | (quot (line . "~A") |
24 | (hdr1 (line . "# ~A~%") | 26 | (stanza . "> ~A~%~%")) |
25 | (stanza . "~A~%")) | 27 | (hdr1 (line . "# ~A~%") |
26 | (hdr2 (line . "## ~A~%") | 28 | (stanza . "~A~%")) |
27 | (stanza . "~A~%")) | 29 | (hdr2 (line . "## ~A~%") |
28 | (hdr3 (line . "### ~A~%") | 30 | (stanza . "~A~%")) |
29 | (stanza . "~A~%")) | 31 | (hdr3 (line . "### ~A~%") |
30 | (meta (line . "") | 32 | (stanza . "~A~%"))))) |
31 | (stanza . "")) | ||
32 | (default | ||
33 | (line . "~A") | ||
34 | (stanza . "~A~%~%")))) | ||
35 | 33 | ||
36 | (define-public filters | 34 | (define-public filters |
37 | ;;; (TYPE (line . LINE-FILTER) (stanza . STANZA-FILTER)) | 35 | (make-parameter |
38 | ;; line-filter : (lambda (list-of-strs) ...) -> list-of-strs (for format) | 36 | ;; (TYPE (line . LINE-FILTER) (stanza . STANZA-FILTER)) |
39 | ;; stanza-filter : (lambda (list-of-strs) ...) -> str | 37 | ;; line-filter : (lambda (list-of-strs) ...) -> list-of-strs (for format) |
40 | `((verb (line . ,identity) | 38 | ;; stanza-filter : (lambda (list-of-strs) ...) -> str |
41 | (stanza . ,(lambda (lines) (apply string-append lines)))) | 39 | `((verb (line . ,identity) |
42 | (default | 40 | (stanza . ,join-lines)) |
43 | (line . ,identity) | 41 | (default |
44 | (stanza . ,(lambda (lines) | 42 | (line . ,identity) |
45 | (irregex-replace/all '(: bol (* space)) | 43 | (stanza . ,flush-lines-left))))) |
46 | (string-join lines) "")))))) | ||
47 | 44 | ||
48 | (define (format-line line el) | 45 | (define (format-line line el) |
49 | (cond | 46 | (cond |
@@ -72,8 +69,10 @@ | |||
72 | (and (eq? scope 'inline) | 69 | (and (eq? scope 'inline) |
73 | (alist-walk alist 'default 'line)))) | 70 | (alist-walk alist 'default 'line)))) |
74 | 71 | ||
75 | (define (get-format el scope) (get-from formats el scope)) | 72 | (define (get-format el scope) |
76 | (define (get-filter el scope) (get-from filters el scope)) | 73 | (or (get-from (formats) el scope) |
74 | "")) | ||
75 | (define (get-filter el scope) (get-from (filters) el scope)) | ||
77 | 76 | ||
78 | (define (sprintf* fmt lis) | 77 | (define (sprintf* fmt lis) |
79 | (let loop ((num (length (irregex-extract "~[aA]" fmt))) | 78 | (let loop ((num (length (irregex-extract "~[aA]" fmt))) |