summaryrefslogtreecommitdiff
path: root/cook
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2024-08-11 16:07:23 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2024-08-11 16:07:23 +0200
commitee37adcf244c4c20c2eb98e2d3538378aa02ac13 (patch)
treed35d8c497e54b62cee4b87a1275b79f68497275e /cook
parent51e18e45c4ac48e8b77fbd7403daa7ba7109675a (diff)
Multiline steps
Diffstat (limited to 'cook')
-rw-r--r--cook/parse.scm22
1 files changed, 14 insertions, 8 deletions
diff --git a/cook/parse.scm b/cook/parse.scm
index f53bca4..2570f61 100644
--- a/cook/parse.scm
+++ b/cook/parse.scm
@@ -67,11 +67,13 @@ https://github.com/cooklang/spec/blob/main/EBNF.md
+(define whitespace-chars (char-set #\space))
(define newline-chars (char-set #\x000A #\x000D #\x0085 #\x2028 #\x2029))
(define punctuation-chars (char-set #\. #\{ #\})) ;; TODO: do it right
(define word-chars (char-set-difference char-set:full
punctuation-chars
- char-set:whitespace))
+ newline-chars
+ whitespace-chars))
(define any-text-chars (char-set-difference char-set:full
newline-chars))
(define text-chars (char-set-difference any-text-chars
@@ -80,14 +82,15 @@ https://github.com/cooklang/spec/blob/main/EBNF.md
(define component-chars (char-set-difference text-chars
(char-set #\{ #\})))
(define component-word-chars (char-set-difference component-chars
- char-set:whitespace))
+ newline-chars
+ whitespace-chars))
(define quantity-chars (char-set-difference text-chars (char-set #\} #\%)))
(define metadata-chars (char-set-difference text-chars (char-set #\:)))
(define-grammar cook
(nl ((: ,newline-chars)))
- (empty-line ((: bol ,nl)))
- (whitespace ((=> x (+ ,char-set:whitespace))
+ (empty-line ((: bol (* ,whitespace-chars) ,nl)))
+ (whitespace ((=> x (+ ,whitespace-chars))
(list->string x)))
(any-text-item ((: (=> c (+ ,any-text-chars)))
@@ -133,13 +136,16 @@ https://github.com/cooklang/spec/blob/main/EBNF.md
(ingredient ((: "@" (=> c ,component))
(component->ingredient c)))
- (step ((: (=> s (+ (or ,ingredient
+ (step-line ((: (? ,whitespace)
+ (=> s (+ (or ,ingredient
,cookware
,timer
,text-item)))
- (or ,empty-line
- (: (* ,empty-line) eos)))
- (make-step s)))
+ (? ,nl))
+ s))
+
+ (step ((: (=> s ,step-line) (=> ns (* ,step-line)))
+ (make-step (concatenate (append (list s) ns)))))
(metadata ((: bol ">>" (* ,whitespace)
(=> k ,meta-key)