aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-06-22 23:33:44 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-06-22 23:33:44 +0200
commit0602655591e911b7e80ee50a4b9f7f88c9044fb1 (patch)
treedbce0f90f452ae5fc8388f5d3c521687bb9a7c8b
parentResolve TODO about calendar styles. (diff)
downloadcalp-0602655591e911b7e80ee50a4b9f7f88c9044fb1.tar.gz
calp-0602655591e911b7e80ee50a4b9f7f88c9044fb1.tar.xz
Rewrote define-define-peg-pattern.
Rewrote it to use define-syntax instead of define-macro. This should resove the weirdness around environment for eval (now compile). Also rename it to define-peg-pattern*.
-rw-r--r--module/c/lex.scm23
1 files changed, 14 insertions, 9 deletions
diff --git a/module/c/lex.scm b/module/c/lex.scm
index d36fcc05..34e52d88 100644
--- a/module/c/lex.scm
+++ b/module/c/lex.scm
@@ -4,14 +4,18 @@
:export (lex))
-;; Like the regular define-peg-pattern. But evaluates the
-;; pattern before treating it as a peg rule.
-(define-macro (define-define-peg-pattern name capture expr)
- `(define-peg-pattern ,name ,capture
- ;; NOTE how does this work if we are in a different module?
- ;; It currently however isn't a problem since we don't export
- ;; this macro.
- ,(eval expr (current-module))))
+;; Like define-peg-pattern, but body is evaluated
+(define-syntax define-peg-pattern*
+ (lambda (stx)
+ (syntax-case stx ()
+ ((_ sym accum pat)
+ #`(define sym
+ (let ((matchf (compile-peg-pattern (datum->syntax #'stx pat) 'accum)))
+ (let ((syn ((@ (ice-9 peg codegen) wrap-parser-for-users) #'stx matchf 'accum 'sym)))
+ ((@ (system base compile) compile)
+ ((@ (ice-9 peg cache) cg-cached-parser)
+ syn)))))))))
+
@@ -61,7 +65,8 @@
(define-peg-pattern char all
(and (ignore "'") (or escaped-char peg-any) (ignore "'")))
-(define-define-peg-pattern operator all
+
+(define-peg-pattern* operator all
`(or ,@(map symbol->string symbol-binary-operators)
,@(map (lambda (op) `(and ,(symbol->string op) ws))
wordy-binary-operators)))