diff --git a/module/ice-9/peg.scm b/module/ice-9/peg.scm index 4f4bbf877..58e35cef8 100644 --- a/module/ice-9/peg.scm +++ b/module/ice-9/peg.scm @@ -67,6 +67,13 @@ execute the STMTs and try again." #f (make-prec 0 (car res) string (string-collapse (cadr res)))))) +(define (peg-extended-compile pattern accum) + (syntax-case pattern (peg) + ((peg str) + (string? (syntax->datum #'str)) + (peg-string-compile #'str (if (eq? accum 'all) 'body accum))) + (else (peg-sexp-compile pattern accum)))) + ;; The results of parsing using a nonterminal are cached. Think of it like a ;; hash with no conflict resolution. Process for deciding on the cache size ;; wasn't very scientific; just ran the benchmarks and stopped a little after @@ -78,7 +85,7 @@ execute the STMTs and try again." (lambda (x) (syntax-case x () ((_ sym accum pat) - (let ((matchf (peg-sexp-compile #'pat (syntax->datum #'accum))) + (let ((matchf (peg-extended-compile #'pat (syntax->datum #'accum))) (accumsym (syntax->datum #'accum)) (c (datum->syntax x (gensym))));; the cache ;; CODE is the code to parse the string if the result isn't cached. diff --git a/module/ice-9/peg/codegen.scm b/module/ice-9/peg/codegen.scm index 0804d1ed4..8dd507cb7 100644 --- a/module/ice-9/peg/codegen.scm +++ b/module/ice-9/peg/codegen.scm @@ -164,9 +164,6 @@ return EXP." (peg-sexp-compile #'pat 'none)) ((capture pat) ;; parse (peg-sexp-compile #'pat 'body)) - ((peg pat) ;; embedded PEG string - (string? (syntax->datum #'pat)) - (peg-string-compile #'pat (baf accum))) ((and pat ...) (cg-and #'(pat ...) (baf accum))) ((or pat ...)