Function: with-peg-rules
with-peg-rules is a macro defined in peg.el.gz.
Signature
(with-peg-rules RULES &rest BODY)
Documentation
Make PEG rules RULES available within the scope of BODY.
RULES is a list of rules of the form (NAME . PEXS), where PEXS is a sequence
of PEG expressions, implicitly combined with and.
RULES can also contain symbols in which case these must name
rulesets defined previously with define-peg-ruleset.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/peg.el.gz
(defmacro with-peg-rules (rules &rest body)
"Make PEG rules RULES available within the scope of BODY.
RULES is a list of rules of the form (NAME . PEXS), where PEXS is a sequence
of PEG expressions, implicitly combined with `and'.
RULES can also contain symbols in which case these must name
rulesets defined previously with `define-peg-ruleset'."
(declare (indent 1) (debug (sexp form))) ;FIXME: `sexp' is not good enough!
(let* ((rulesets nil)
(rules
;; First, macroexpand the rules.
(delq nil
(mapcar (lambda (rule)
(if (symbolp rule)
(progn (push rule rulesets) nil)
(cons (car rule) (peg-normalize `(and . ,(cdr rule))))))
rules)))
(ctx (assq :peg-rules macroexpand-all-environment))
(body
(macroexpand-all
`(cl-labels
,(mapcar (lambda (rule)
;; FIXME: Use `peg--lambda' as well.
`(,(peg--rule-id (car rule))
()
,(peg--translate-rule-body (car rule) (cdr rule))))
rules)
,@body)
`((:peg-rules ,@(append rules (cdr ctx)))
,@macroexpand-all-environment))))
(if (null rulesets)
body
`(cl-flet ,(mapcan (lambda (ruleset)
(let ((aliases (get ruleset 'peg--rules)))
(unless aliases
(message "Unknown PEG ruleset: %S" ruleset))
(copy-sequence aliases)))
rulesets)
,body))))