diff options
author | Noah Lavine <nlavine@haverford.edu> | 2011-01-31 15:08:32 -0500 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2013-01-16 10:11:33 +0100 |
commit | 8e8de46ec60ee61d0b9f6a05cb5d52f55c58dbdd (patch) | |
tree | e9211a99e4b99709faf572980a8040de28acc8c5 /module/ice-9/peg.scm | |
parent | 00e227f7799de4f338670af56cb58d42001fd5a9 (diff) | |
download | guile-8e8de46ec60ee61d0b9f6a05cb5d52f55c58dbdd.tar.gz |
peg: cg-or, cg-or-int return syntax
* module/ice-9/peg.scm (cg-or, cg-or-int): Return syntax instead of
s-expressions.
(peg-sexp-compile): Adapt.
Diffstat (limited to 'module/ice-9/peg.scm')
-rw-r--r-- | module/ice-9/peg.scm | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/module/ice-9/peg.scm b/module/ice-9/peg.scm index 160d87bfe..c21cd78ee 100644 --- a/module/ice-9/peg.scm +++ b/module/ice-9/peg.scm @@ -276,8 +276,7 @@ ((eq? (car match) 'and) (cg-and for-syntax (cdr match) (baf accum))) ((eq? (car match) 'or) - (datum->syntax for-syntax - (cg-or for-syntax (cdr match) (baf accum)))) + (cg-or for-syntax (cdr match) (baf accum))) ((eq? (car match) 'body) (if (not (= (length match) 4)) (datum->syntax for-syntax @@ -331,23 +330,23 @@ ;; Top-level function builder for OR. Reduces to a call to CG-OR-INT. (define (cg-or for-syntax arglst accum) - (safe-bind - (str strlen at body) - `(lambda (,str ,strlen ,at) - ,(cg-or-int for-syntax arglst accum str strlen at body)))) + (let ((str (syntax str)) + (strlen (syntax strlen)) + (at (syntax at)) + (body (syntax body))) + #`(lambda (#,str #,strlen #,at) + #,(cg-or-int for-syntax arglst accum str strlen at body)))) ;; Internal function builder for OR (calls itself). (define (cg-or-int for-syntax arglst accum str strlen at body) - (safe-bind - (res) + (let ((res (syntax res))) (if (null? arglst) #f ;; base case - (let ((mf (syntax->datum - (peg-sexp-compile for-syntax (car arglst) accum)))) - `(let ((,res (,mf ,str ,strlen ,at))) - (if ,res ;; if the match succeeds, we're done - ,(cggr for-syntax accum 'cg-or `(cadr ,res) `(car ,res)) - ,(cg-or-int for-syntax (cdr arglst) accum str strlen at body))))))) + (let ((mf (peg-sexp-compile for-syntax (car arglst) accum))) + #`(let ((#,res (#,mf #,str #,strlen #,at))) + (if #,res ;; if the match succeeds, we're done + #,(cggr-syn for-syntax accum 'cg-or #`(cadr #,res) #`(car #,res)) + #,(cg-or-int for-syntax (cdr arglst) accum str strlen at body))))))) ;; Returns a block of code that tries to match MATCH, and on success updates AT ;; and BODY, return #f on failure and #t on success. |