peg: more syntax helper cleanup
authorAndy Wingo <wingo@pobox.com>
Thu, 17 Feb 2011 13:06:08 +0000 (14:06 +0100)
committerAndy Wingo <wingo@pobox.com>
Wed, 16 Jan 2013 09:11:36 +0000 (10:11 +0100)
* module/ice-9/peg.scm (single-filter, push-not-null!): Use
  syntax-rules, and move outside the eval-when.

module/ice-9/peg.scm

index 831a78e..ebea740 100644 (file)
@@ -48,7 +48,7 @@
   (syntax-rules ()
     ((_ test stmt stmt* ...)
      (let lp ()
-       (or action
+       (or test
            (begin stmt stmt* ... (lp)))))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     ((_ lst obj)
      (set! lst (cons obj lst)))))
 
+;; If SYM is a list of one element, return (car SYM), else return SYM.
+(define-syntax single-filter
+  (syntax-rules ()
+    ((_ exp)
+     (pmatch exp
+       ((,elt) elt)
+       (,elts elts)))))
+
+;; If OBJ is non-null, push it onto LST, otherwise do nothing.
+(define-syntax push-not-null!
+  (syntax-rules ()
+    ((_ lst obj)
+     (if (not (null? obj))
+         (push! lst obj)))))
+
 (eval-when (compile load eval)
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (else (datum->syntax for-syntax
                       (error-val `(peg-sexp-compile-error-3 ,match ,accum))))))
 
-;;;;; Convenience macros for making sure things come out in a readable form.
-;; If SYM is a list of one element, return (car SYM), else return SYM.
-(define-syntax single-filter
-  (lambda (x)
-    (syntax-case x ()
-      ((_ sym)
-       #'(if (single? sym) (car sym) sym)))))
-;; If OBJ is non-null, push it onto LST, otherwise do nothing.
-(define-syntax push-not-null!
-  (lambda (x)
-    (syntax-case x ()
-      ((_ lst obj)
-       #'(if (not (null? obj)) (push! lst obj))))))
-
 ;; Top-level function builder for AND.  Reduces to a call to CG-AND-INT.
 (define (cg-and for-syntax arglst accum)
    #`(lambda (str strlen at)