1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-09 13:30:26 +02:00

peg; syntax helper cleanups

* module/ice-9/peg.scm (until, single?, push!): Move outside the
  eval-when.  Use syntax-rules, and single? is faster now.
This commit is contained in:
Andy Wingo 2011-02-17 13:49:28 +01:00
parent 3c8963de27
commit b5ebb8abad

View file

@ -35,10 +35,9 @@
peg:substring
peg-record?
keyword-flatten)
#:use-module (system base pmatch)
#:use-module (ice-9 pretty-print))
(eval-when (compile load eval)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;; LOOPING CONSTRUCTS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -50,7 +49,7 @@
((_ test stmt stmt* ...)
(let lp ()
(or action
(begin stmt stmt* (lp)))))))
(begin stmt stmt* ... (lp)))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;; GENERIC LIST-PROCESSING MACROS
@ -59,17 +58,19 @@
;; Return #t if the list has only one element (calling length all the time on
;; potentially long lists was really slow).
(define-syntax single?
(lambda (x)
(syntax-case x ()
((_ lst)
#'(and (list? lst) (not (null? lst)) (null? (cdr lst)))))))
(syntax-rules ()
((_ x)
(pmatch x
((_) #t)
(else #f)))))
;; Push an object onto a list.
(define-syntax push!
(lambda (x)
(syntax-case x ()
(syntax-rules ()
((_ lst obj)
#'(set! lst (cons obj lst))))))
(set! lst (cons obj lst)))))
(eval-when (compile load eval)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;; CODE GENERATORS