add whitespace to grammar

main
Matthew Butterick 8 years ago
parent 6f1febab17
commit f0de2a1e84

@ -8,4 +8,4 @@ multicolumn : multiblock [/BLOCK-BREAK multiblock]*
multiblock : multiline [/LINE-BREAK multiline]*
multiline : QUAD*
multiline : /WHITESPACE* (QUAD [WHITESPACE+ QUAD]*)* /WHITESPACE*

@ -8,11 +8,14 @@
(cond
[(symbol? x) (token x #f)]
[(string? x)
(map (λ(xi) (token 'QUAD (quad attrs xi))) (string->list x))]
(for/list ([c (in-string x)])
(case c
[(#\space #\newline #\return) (token 'WHITESPACE (quad attrs c))]
[else (token 'QUAD (quad attrs c))]))]
[else
(map (λ(xi) (loop xi ((quad-attrs x) . override-with . attrs))) (quad-list x))]))))
(map (λ(xi) (loop xi ((quad-attrs x) . override-with . attrs))) (quad-list x))]))))
(module+ test
(require rackunit)
(require rackunit "parse.rkt")
(tokenize (quad (attrs #:size 10 #:font "Eq") "ba" (line-break) "r" (quad (attrs #:size 8) "zam") "q\tux"))
(tokenize (quad #f "Meg is" (block-break) " an ally.")))
(syntax->datum (parse (tokenize (quad #f "Meg is " (line-break) "\nan ally.")))))

Loading…
Cancel
Save