1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-23 13:00:34 +02:00

peg: lower datum->syntax in cg-range case

* module/ice-9/peg.scm (cg-range): Datum->syntax here...
  (peg-sexp-compile): ...instead of here.
This commit is contained in:
Noah Lavine 2011-01-30 16:10:07 -05:00 committed by Andy Wingo
parent 6a297af101
commit 0b61da75fe

View file

@ -184,15 +184,18 @@
;; Generates code for matching a range of characters between start and end. ;; Generates code for matching a range of characters between start and end.
;; E.g.: (cg-range syntax #\a #\z 'body) ;; E.g.: (cg-range syntax #\a #\z 'body)
(define (cg-range for-syntax start end accum) (define (cg-range for-syntax start end accum)
(safe-bind (let ((str (syntax str))
(str strlen at c) (strlen (syntax strlen))
(cggl for-syntax str strlen at (at (syntax at))
`(let ((,c (string-ref ,str ,at))) (c (syntax c)))
(if (and (datum->syntax for-syntax
(char>=? ,c ,start) (cggl for-syntax str strlen at
(char<=? ,c ,end)) `(let ((,c (string-ref ,str ,at)))
,(cggr for-syntax accum 'cg-range `(string ,c) `(+ ,at 1)) (if (and
#f))))) (char>=? ,c ,start)
(char<=? ,c ,end))
,(cggr for-syntax accum 'cg-range `(string ,c) `(+ ,at 1))
#f))))))
;; Filters the accum argument to peg-sexp-compile for buildings like string ;; Filters the accum argument to peg-sexp-compile for buildings like string
;; literals (since we don't want to tag them with their name if we're doing an ;; literals (since we don't want to tag them with their name if we're doing an
@ -228,8 +231,7 @@
(error-val `(peg-sexp-compile-error-1 ,match ,accum)))) (error-val `(peg-sexp-compile-error-1 ,match ,accum))))
((eq? (car match) 'range) ;; range of characters (e.g. [a-z]) ((eq? (car match) 'range) ;; range of characters (e.g. [a-z])
(datum->syntax for-syntax (cg-range for-syntax (cadr match) (caddr match) (baf accum)))
(cg-range for-syntax (cadr match) (caddr match) (baf accum))))
((eq? (car match) 'ignore) ;; match but don't parse ((eq? (car match) 'ignore) ;; match but don't parse
(peg-sexp-compile for-syntax (cadr match) 'none)) (peg-sexp-compile for-syntax (cadr match) 'none))
((eq? (car match) 'capture) ;; parse ((eq? (car match) 'capture) ;; parse