diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2024-08-12 23:24:56 +0200 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2024-08-12 23:24:56 +0200 |
commit | f44e4dc849de4c6d5f64d4fac812e424e4c193c2 (patch) | |
tree | 9b4990c66d97e73d6a2820fe8f054219775e5cb3 /cook | |
parent | 2bba3d3de5a8cefe233f274fa2d8a2ba69799760 (diff) |
parse: trim some amounts and metadata key/vals
Diffstat (limited to 'cook')
-rw-r--r-- | cook/parse-internals.sld | 3 | ||||
-rw-r--r-- | cook/parse.scm | 21 | ||||
-rw-r--r-- | cook/parse.sld | 3 |
3 files changed, 17 insertions, 10 deletions
diff --git a/cook/parse-internals.sld b/cook/parse-internals.sld index 6094fe1..1728f1d 100644 --- a/cook/parse-internals.sld +++ b/cook/parse-internals.sld @@ -7,7 +7,8 @@ (chibi char-set ascii) (chibi char-set) (chibi parse) - (chibi regexp)) + (chibi regexp) + (chibi string)) (export amount? amount-quantity amount-unit diff --git a/cook/parse.scm b/cook/parse.scm index 2071fdd..46313b0 100644 --- a/cook/parse.scm +++ b/cook/parse.scm @@ -122,11 +122,15 @@ https://github.com/cooklang/spec/blob/main/EBNF.md (make-comment (list->string c)))) (word ((=> w (+ ,word-chars)) - (list->string w))) - (unit ((=> u (+ ,unit-chars)) - (list->string u))) - (quantity ((=> q (+ ,quantity-chars)) - (string->number (list->string q)))) + w)) + (unit ((=> u ,(parse-map-substring + (parse-repeat+ (parse-char unit-chars)) + string-trim)) + u)) + (quantity ((=> q ,(parse-map-substring + (parse-repeat+ (parse-char quantity-chars)) + string-trim)) + (or (string->number q) q))) (meta-key ((=> k (+ ,metadata-chars)) (list->string k))) @@ -179,10 +183,11 @@ https://github.com/cooklang/spec/blob/main/EBNF.md (concatenate! x)))))) (make-step (merge-step-strings (concatenate! s))))) - (metadata ((: bol ">>" (* ,whitespace) - (=> k ,meta-key) + (metadata ((: bol ">>" + (=> k ,(parse-map meta-key string-trim)) (* ,whitespace) ":" (* ,whitespace) - (=> v ,any-text-item) (* ,whitespace) eol) + (=> v ,(parse-map any-text-item string-trim)) + (* ,whitespace) eol) (make-metadata-line k v))) (element ((or ,metadata ,comment ,step))) diff --git a/cook/parse.sld b/cook/parse.sld index 4fb4c3f..1dcfb35 100644 --- a/cook/parse.sld +++ b/cook/parse.sld @@ -7,7 +7,8 @@ (chibi char-set ascii) (chibi char-set) (chibi parse) - (chibi regexp)) + (chibi regexp) + (chibi string)) (export amount? amount-quantity amount-unit |