From 759a77f91f9d0e908e10b513d5cda8a2f78ee776 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Mon, 12 Aug 2024 01:14:52 +0200 Subject: Merge comment characters in strings --- cook/parse-internals.sld | 6 +++--- cook/parse.scm | 14 +++++++++++++- cook/parse.sld | 3 ++- 3 files changed, 18 insertions(+), 5 deletions(-) (limited to 'cook') 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) -- cgit v1.2.3