From f44e4dc849de4c6d5f64d4fac812e424e4c193c2 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Mon, 12 Aug 2024 23:24:56 +0200 Subject: parse: trim some amounts and metadata key/vals --- cook/parse.scm | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'cook/parse.scm') 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))) -- cgit v1.2.3