1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-09 21:40:33 +02:00

Separate PEG Concerns

* module/ice-9/peg/codegen.scm: peg-sexp-compile no longer knows about
   string PEGs
* module/ice-9/peg.scm: add a new function peg-extended-compile that
   calls peg-sexp-compile or peg-string-compile on its argument as
   appropriate
This commit is contained in:
Noah Lavine 2011-03-28 15:18:27 -04:00 committed by Andy Wingo
parent 0afaf59982
commit bbc5564c42
2 changed files with 8 additions and 4 deletions

View file

@ -67,6 +67,13 @@ execute the STMTs and try again."
#f #f
(make-prec 0 (car res) string (string-collapse (cadr res)))))) (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 ;; 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 ;; 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 ;; 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) (lambda (x)
(syntax-case x () (syntax-case x ()
((_ sym accum pat) ((_ 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)) (accumsym (syntax->datum #'accum))
(c (datum->syntax x (gensym))));; the cache (c (datum->syntax x (gensym))));; the cache
;; CODE is the code to parse the string if the result isn't cached. ;; CODE is the code to parse the string if the result isn't cached.

View file

@ -164,9 +164,6 @@ return EXP."
(peg-sexp-compile #'pat 'none)) (peg-sexp-compile #'pat 'none))
((capture pat) ;; parse ((capture pat) ;; parse
(peg-sexp-compile #'pat 'body)) (peg-sexp-compile #'pat 'body))
((peg pat) ;; embedded PEG string
(string? (syntax->datum #'pat))
(peg-string-compile #'pat (baf accum)))
((and pat ...) ((and pat ...)
(cg-and #'(pat ...) (baf accum))) (cg-and #'(pat ...) (baf accum)))
((or pat ...) ((or pat ...)