summaryrefslogtreecommitdiff
path: root/cook
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2024-08-12 10:53:53 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2024-08-12 10:53:53 +0200
commit9edce9caa52adb556b7fc2482f005744212e2fc6 (patch)
tree67a6fe87cf3fc337efdd292f081fa5055136e0f5 /cook
parent759a77f91f9d0e908e10b513d5cda8a2f78ee776 (diff)
Full recipe parsing to a structure
Diffstat (limited to 'cook')
-rw-r--r--cook/debug.sld3
-rw-r--r--cook/parse-internals.sld3
-rw-r--r--cook/parse.scm10
-rw-r--r--cook/parse.sld3
4 files changed, 18 insertions, 1 deletions
diff --git a/cook/debug.sld b/cook/debug.sld
index 6b7ef33..638c13a 100644
--- a/cook/debug.sld
+++ b/cook/debug.sld
@@ -26,6 +26,9 @@
(list 'step (map cook->list (step-elements y))))
((hash-table? y)
(list 'metadata (cook->list (hash-table->alist y))))
+ ((recipe? y)
+ (list 'recipe (cook->list (recipe-metadata y))
+ (cook->list (recipe-body y))))
((list? y)
(map cook->list y))
(else y)))))
diff --git a/cook/parse-internals.sld b/cook/parse-internals.sld
index 94986b6..6094fe1 100644
--- a/cook/parse-internals.sld
+++ b/cook/parse-internals.sld
@@ -26,6 +26,9 @@
metadata-line?
metadata-line-key
metadata-line-value
+ recipe?
+ recipe-metadata
+ recipe-body
step?
step-elements
comment?
diff --git a/cook/parse.scm b/cook/parse.scm
index bfb50a7..2ccc4a6 100644
--- a/cook/parse.scm
+++ b/cook/parse.scm
@@ -56,6 +56,12 @@ https://github.com/cooklang/spec/blob/main/EBNF.md
comment?
(text comment-text))
+(define-record-type <recipe>
+ (make-recipe metadata body)
+ recipe?
+ (metadata recipe-metadata)
+ (body recipe-body))
+
(define (metadata-line-list->hash-table meta-lines)
(let ((metadata (make-hash-table)))
(for-each (lambda (line)
@@ -176,4 +182,6 @@ https://github.com/cooklang/spec/blob/main/EBNF.md
(concatenate els))))
(define (parse-cook str)
- (parse-fully recipe str))
+ (let ((lis (parse-fully recipe str)))
+ (let-values (((meta-lines body) (partition metadata-line? lis)))
+ (make-recipe (metadata-line-list->hash-table meta-lines) body))))
diff --git a/cook/parse.sld b/cook/parse.sld
index ab7730d..4fb4c3f 100644
--- a/cook/parse.sld
+++ b/cook/parse.sld
@@ -24,5 +24,8 @@
comment-text
step?
step-elements
+ recipe?
+ recipe-metadata
+ recipe-body
parse-cook)
(include "parse.scm"))