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-internals.sld | 3 ++- cook/parse.scm | 21 +++++++++++++-------- 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 -- cgit v1.2.3