summaryrefslogtreecommitdiff
path: root/cook
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2024-08-11 11:50:19 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2024-08-11 12:32:11 +0200
commitc0f318ef59986451ee0844e5cec1f24f2a623f37 (patch)
tree85be893012822f407cf795fa8ee155ce10e2375f /cook
parent7ec53b944c73708344f736b974801713693483ec (diff)
Fix component parsing
Diffstat (limited to 'cook')
-rw-r--r--cook/parse.scm23
1 files changed, 15 insertions, 8 deletions
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)))