summaryrefslogtreecommitdiff
path: root/cook
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2024-08-12 01:14:52 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2024-08-12 01:15:01 +0200
commit759a77f91f9d0e908e10b513d5cda8a2f78ee776 (patch)
tree823f0051cc1b94e9a698da0801a966f068480994 /cook
parent2bf752040928be5933a819b0ea10e2d3812c2eed (diff)
Merge comment characters in strings
Diffstat (limited to 'cook')
-rw-r--r--cook/parse-internals.sld6
-rw-r--r--cook/parse.scm14
-rw-r--r--cook/parse.sld3
3 files changed, 18 insertions, 5 deletions
diff --git a/cook/parse-internals.sld b/cook/parse-internals.sld
index 99160fd..94986b6 100644
--- a/cook/parse-internals.sld
+++ b/cook/parse-internals.sld
@@ -1,13 +1,13 @@
(define-library (cook parse-internals)
- (import (srfi 1)
+ (import (scheme base)
+ (srfi 1)
(srfi 9)
(srfi 69)
(chibi)
(chibi char-set ascii)
(chibi char-set)
(chibi parse)
- (chibi regexp)
- (chibi parse common))
+ (chibi regexp))
(export amount?
amount-quantity
amount-unit
diff --git a/cook/parse.scm b/cook/parse.scm
index b18afba..bfb50a7 100644
--- a/cook/parse.scm
+++ b/cook/parse.scm
@@ -65,6 +65,18 @@ https://github.com/cooklang/spec/blob/main/EBNF.md
meta-lines)
metadata))
+(define (merge-step-strings lis)
+ (reduce-right
+ (lambda (el acc)
+ (cond
+ ((char? el)
+ (if (and (< 0 (length acc)) (string? (car acc)))
+ (cons (string-append (string el) (car acc)) (cdr acc))
+ (append (list (string el)) acc)))
+ (else
+ (append (list el) acc))))
+ '()
+ lis))
(define whitespace-chars (char-set #\space))
@@ -146,7 +158,7 @@ https://github.com/cooklang/spec/blob/main/EBNF.md
(append (concatenate s) (if n '(#\space) '()))))
(step ((: (=> s ,step-line) (=> ns (* ,step-line)))
- (make-step (concatenate (append (list s) ns)))))
+ (make-step (merge-step-strings (concatenate (append (list s) ns))))))
(metadata ((: bol ">>" (* ,whitespace)
(=> k ,meta-key)
diff --git a/cook/parse.sld b/cook/parse.sld
index e9805c3..ab7730d 100644
--- a/cook/parse.sld
+++ b/cook/parse.sld
@@ -1,5 +1,6 @@
(define-library (cook parse)
- (import (srfi 1)
+ (import (scheme base)
+ (srfi 1)
(srfi 9)
(srfi 69)
(chibi)