summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)