From e31c5559b8e58965a6d50fc767a8401d0bafc7d1 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Sun, 11 Aug 2024 22:03:00 +0200 Subject: Make parse work with many empty lines --- cook/parse.scm | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'cook') diff --git a/cook/parse.scm b/cook/parse.scm index 05b3a2a..098b866 100644 --- a/cook/parse.scm +++ b/cook/parse.scm @@ -89,7 +89,6 @@ https://github.com/cooklang/spec/blob/main/EBNF.md (define-grammar cook (nl ((: ,newline-chars))) - (empty-line ((: bol (* ,whitespace-chars) ,nl))) (whitespace ((=> x (+ ,whitespace-chars)) (list->string x))) @@ -147,6 +146,8 @@ https://github.com/cooklang/spec/blob/main/EBNF.md (concatenate s))) (step ((: (=> s ,step-line) (=> ns (* ,step-line))) + ;; TODO It's not converting the end of the step-line to a + ;; space (make-step (concatenate (append (list s) ns))))) (metadata ((: bol ">>" (* ,whitespace) @@ -155,12 +156,14 @@ https://github.com/cooklang/spec/blob/main/EBNF.md (=> v ,any-text-item) (* ,whitespace) eol) (make-metadata-line k v))) - (recipe ((* (or (: (=> m (+ ,metadata)) ,nl) - (=> c (+ ,comment)) - (: (=> s (+ ,step)) (or eos (* ,empty-line))))) - (list 'recipe - (metadata-line-list->hash-table (or m '())) - s)))) + (element ((or ,metadata ,comment ,step))) + + (recipe ((=> els + (* (: ,element ,(parse-ignore + (parse-seq + (parse-repeat nl) + (parse-optional parse-end)))))) + (concatenate els)))) (define (parse-cook str) (parse-fully recipe str)) -- cgit v1.2.3