diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2025-05-04 00:07:03 +0200 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2025-05-04 00:07:03 +0200 |
commit | abf15a6595d5f5ad5700823389992b0efd66f312 (patch) | |
tree | a7670992422711d9c70ee0cf1ff05c5c91a409ce /cook/parse.scm | |
parent | 0513b006525c3e78f749121a5d1e7fbebd1a20bc (diff) |
parse: accept newlines in components
Diffstat (limited to 'cook/parse.scm')
-rw-r--r-- | cook/parse.scm | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/cook/parse.scm b/cook/parse.scm index 4f9eea8..54ea23c 100644 --- a/cook/parse.scm +++ b/cook/parse.scm @@ -104,7 +104,8 @@ https://github.com/cooklang/spec/blob/main/EBNF.md (define text-chars (char-set-difference any-text-chars (char-set #\@ #\# #\~))) (define unit-chars (char-set-difference text-chars (char-set #\}))) -(define component-chars text-chars) +(define component-chars (char-set-difference char-set:full + (char-set #\@ #\# #\~))) (define component-word-chars (char-set-difference component-chars punctuation-chars newline-chars @@ -120,6 +121,9 @@ https://github.com/cooklang/spec/blob/main/EBNF.md (define string-trim-whitespace (string-trimmer-from-sets whitespace-chars)) +(define (string-split-newline str) + (string-split str (lambda (x) (char-set-contains? newline-chars x)))) + (define-grammar cook (one-nl (,(parse-map (parse-sre `(: eol (+ ,newline-chars) bol)) @@ -172,7 +176,10 @@ https://github.com/cooklang/spec/blob/main/EBNF.md (? (: (=> cc (* ,component-chars)) (=> a ,amount-block)))) (make-component - (string-append cw (if cc (list->string cc) "")) + (string-join + (string-split-newline + (string-append cw (if cc (list->string cc) ""))) + " ") a))) (timer ((: "~" (=> c (or ,component ,no-word-component))) |