From abf15a6595d5f5ad5700823389992b0efd66f312 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Sun, 4 May 2025 00:07:03 +0200 Subject: parse: accept newlines in components --- cook/parse.scm | 11 +++++++++-- 1 file 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))) -- cgit v1.2.3