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:
parent
6a297af101
commit
0b61da75fe
1 changed files with 13 additions and 11 deletions
|
@ -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))
|
||||||
|
(at (syntax at))
|
||||||
|
(c (syntax c)))
|
||||||
|
(datum->syntax for-syntax
|
||||||
(cggl for-syntax str strlen at
|
(cggl for-syntax str strlen at
|
||||||
`(let ((,c (string-ref ,str ,at)))
|
`(let ((,c (string-ref ,str ,at)))
|
||||||
(if (and
|
(if (and
|
||||||
(char>=? ,c ,start)
|
(char>=? ,c ,start)
|
||||||
(char<=? ,c ,end))
|
(char<=? ,c ,end))
|
||||||
,(cggr for-syntax accum 'cg-range `(string ,c) `(+ ,at 1))
|
,(cggr for-syntax accum 'cg-range `(string ,c) `(+ ,at 1))
|
||||||
#f)))))
|
#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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue