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

peg: split define-nonterm into two functions for better readability.

* module/ice-9/peg.scm (define-nonterm): Split for readability.
This commit is contained in:
Noah Lavine 2011-01-29 12:40:37 -05:00 committed by Andy Wingo
parent add20d35be
commit f4576d8161

View file

@ -365,18 +365,7 @@
;; the point of diminishing returns on my box.
(define *cache-size* 512)
;; Defines a new nonterminal symbol accumulating with ACCUM.
(define-syntax define-nonterm
(lambda (x)
(syntax-case x ()
((_ sym accum match)
(let ((matchf (peg-sexp-compile (syntax->datum #'match)
(syntax->datum #'accum)))
(symsym (syntax->datum #'sym))
(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.
(let ((code
(define (code-for-non-cache-case matchf accumsym symsym)
(safe-bind
(str strlen at res body)
`(lambda (,str ,strlen ,at)
@ -402,7 +391,20 @@
((eq? accumsym 'none) `(list (car ,res) '()))
(#t (begin res))))
;; If we didn't match, just return false.
#f))))))
#f)))))
;; Defines a new nonterminal symbol accumulating with ACCUM.
(define-syntax define-nonterm
(lambda (x)
(syntax-case x ()
((_ sym accum match)
(let ((matchf (peg-sexp-compile (syntax->datum #'match)
(syntax->datum #'accum)))
(symsym (syntax->datum #'sym))
(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.
(let ((code (code-for-non-cache-case matchf accumsym symsym)))
#`(begin
(define #,c (make-vector *cache-size* #f));; the cache
(define (sym str strlen at)