From 458017a291d200b736efe5d4b8dcb6789eb08b3a Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Sat, 3 May 2025 22:59:56 +0200 Subject: cook: add section markers --- cook/debug.sld | 2 ++ cook/parse-internals.sld | 4 ++++ cook/parse.scm | 13 ++++++++++++- cook/parse.sld | 2 ++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cook/debug.sld b/cook/debug.sld index 1f4f803..5b6ddb2 100644 --- a/cook/debug.sld +++ b/cook/debug.sld @@ -15,6 +15,8 @@ (list 'comment text)) (($ text) (list 'note text)) + (($
name) + (list 'section name)) (($ name amount) (list 'component name (cook->list amount))) (($ name amount) diff --git a/cook/parse-internals.sld b/cook/parse-internals.sld index 01cf5c2..bed300c 100644 --- a/cook/parse-internals.sld +++ b/cook/parse-internals.sld @@ -47,6 +47,9 @@ note? note-text +
+ section? + section-name ;; Functions parse-cook nl @@ -65,6 +68,7 @@ timer cookware ingredient + section step metadata recipe) diff --git a/cook/parse.scm b/cook/parse.scm index e53ce9f..498b055 100644 --- a/cook/parse.scm +++ b/cook/parse.scm @@ -61,6 +61,11 @@ https://github.com/cooklang/spec/blob/main/EBNF.md note? (text note-text)) +(define-record-type
+ (make-section name) + section? + (name section-name)) + (define-record-type (make-recipe metadata body) recipe? @@ -192,6 +197,12 @@ https://github.com/cooklang/spec/blob/main/EBNF.md (concatenate! x)))))) (make-step (merge-step-strings (concatenate! s))))) + (section ((: "=" (=> c (+ ,any-text-chars)) (or eos ,nl)) + (make-section (string-trim (list->string c) + (lambda (x) + (or (char=? x #\space) + (char=? x #\=))))))) + (metadata ((: bol ">>" (=> k ,(parse-map meta-key string-trim)) (* ,whitespace) ":" (* ,whitespace) @@ -199,7 +210,7 @@ https://github.com/cooklang/spec/blob/main/EBNF.md (* ,whitespace) eol) (make-metadata-line k v))) - (element ((or ,metadata ,comment ,note ,step))) + (element ((or ,metadata ,comment ,note ,section ,step))) (recipe ((=> els (* (: ,element ,(parse-ignore diff --git a/cook/parse.sld b/cook/parse.sld index 17ae1b6..20de41a 100644 --- a/cook/parse.sld +++ b/cook/parse.sld @@ -26,6 +26,8 @@ comment-text note? note-text + section? + section-name step? step-elements recipe? -- cgit v1.2.3