From c0f318ef59986451ee0844e5cec1f24f2a623f37 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Sun, 11 Aug 2024 11:50:19 +0200 Subject: Fix component parsing --- cook/parse.scm | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'cook') diff --git a/cook/parse.scm b/cook/parse.scm index 2953b70..b5f994d 100644 --- a/cook/parse.scm +++ b/cook/parse.scm @@ -77,7 +77,10 @@ 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 (char-set-difference text-chars (char-set #\{ #\}))) +(define component-chars (char-set-difference text-chars + (char-set #\{ #\}))) +(define component-word-chars (char-set-difference component-chars + char-set:whitespace)) (define quantity-chars (char-set-difference text-chars (char-set #\} #\%))) (define metadata-chars (char-set-difference text-chars (char-set #\:))) @@ -110,13 +113,17 @@ https://github.com/cooklang/spec/blob/main/EBNF.md ((=> q ,quantity) (make-amount q #f))) - (no-word-component ((: (=> x (? ,component-chars)) - "{" (? (=> a ,amount)) "}") - (make-component (list->string x) a))) - (component ((: (=> x (+ ,word)) (? (:"{" (=> a ,amount) "}"))) - (make-component x a)) - ((: (=> x (+ ,component-chars)) "{" (? (=> a ,amount)) "}") - (make-component (list->string x) a))) + (no-word-component ((: "{" (? (=> a ,amount)) "}") + (make-component #f a))) + + (component-word ((=> w (+ ,component-word-chars)) + (list->string w))) + (component ((: (=> cw ,component-word) + (? (: (=> cc (* ,component-chars)) + "{" (? (=> a ,amount)) "}"))) + (make-component + (string-append cw (if cc (list->string cc) "")) + a))) (timer ((: "~" (=> c (or ,component ,no-word-component))) (component->timer c))) -- cgit v1.2.3