summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2025-05-03 22:59:56 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2025-05-03 22:59:56 +0200
commit458017a291d200b736efe5d4b8dcb6789eb08b3a (patch)
tree74aad82c2a138b17e3d75c8290907fb94f01444e
parent8a221325935df057c89938de69e6393c3aec62d5 (diff)
cook: add section markers
-rw-r--r--cook/debug.sld2
-rw-r--r--cook/parse-internals.sld4
-rw-r--r--cook/parse.scm13
-rw-r--r--cook/parse.sld2
4 files changed, 20 insertions, 1 deletions
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))
(($ <note> text)
(list 'note text))
+ (($ <section> name)
+ (list 'section name))
(($ <component> name amount)
(list 'component name (cook->list amount)))
(($ <cookware> 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?
note-text
+ <section>
+ 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 <section>
+ (make-section name)
+ section?
+ (name section-name))
+
(define-record-type <recipe>
(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?