From 518fb8205ae251e10d642fc8816f0a6720e3b440 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Sat, 10 Aug 2024 16:04:45 +0200 Subject: Make some project structure --- cook/parse.scm | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'cook/parse.scm') diff --git a/cook/parse.scm b/cook/parse.scm index 8403221..33bf3b0 100644 --- a/cook/parse.scm +++ b/cook/parse.scm @@ -1,11 +1,3 @@ -(import (srfi 1) - (srfi 9) - (srfi 69) - (chibi char-set ascii) - (chibi char-set) - (chibi parse) - (chibi regexp) - (chibi parse common)) #| https://github.com/cooklang/spec/blob/main/EBNF.md |# @@ -69,27 +61,31 @@ https://github.com/cooklang/spec/blob/main/EBNF.md metadata)) + (define newline-chars (char-set #\x000A #\x000D #\x0085 #\x2028 #\x2029)) (define punctuation-chars (char-set #\. #\{ #\})) ;; TODO: do it right (define word-chars (char-set-difference char-set:full punctuation-chars char-set:whitespace)) -(define text-chars (char-set-difference char-set:full - (char-set #\@ #\# #\~) +(define any-text-chars (char-set-difference char-set:full newline-chars)) +(define text-chars (char-set-difference any-text-chars + (char-set #\@ #\# #\~))) (define unit-chars (char-set-difference text-chars (char-set #\}))) (define component-chars (char-set-difference text-chars (char-set #\{ #\}))) (define quantity-chars (char-set-difference text-chars (char-set #\} #\%))) (define metadata-chars (char-set-difference text-chars (char-set #\:))) (define-grammar cook - (newline ((+ ,newline-chars))) + (nl ((+ ,newline-chars))) (whitespace ((+ ,char-set:whitespace))) + (any-text-item ((: (=> c (+ ,any-text-chars))) + (list->string c))) (text-item ((: (=> c (+ ,text-chars))) (list->string c))) - (comment ((: "--" (=> c (+ ,text-chars)) ,newline) + (comment ((: "--" (=> c (+ ,any-text-chars)) ,nl) (list->string c)) ((: "[-" (=> c (* any)) "-]") (list->string c))) @@ -127,16 +123,18 @@ https://github.com/cooklang/spec/blob/main/EBNF.md ,cookware ,timer ,text-item))) - ,newline) + ,nl) (make-step s))) (metadata ((: bol ">>" (* ,whitespace) (=> k ,meta-key) (* ,whitespace) ":" (* ,whitespace) - (=> v ,text-item) (* ,whitespace) ,newline) + (=> v ,any-text-item) (* ,whitespace) ,nl) (make-metadata-line k v))) - (recipe ((* (or (=> m (+ ,metadata)) (=> s (+ ,step)))) + (recipe ((* (or (=> m (+ ,metadata)) + (=> c (+ ,comment))) + (=> s (+ ,step))) (list 'recipe (metadata-line-list->hash-table m) s)))) (define (parse-cook str) -- cgit v1.2.3