summaryrefslogtreecommitdiff
path: root/cook
diff options
context:
space:
mode:
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"))