Function: define-peg-rule
define-peg-rule is a macro defined in peg.el.gz.
Signature
(define-peg-rule NAME ARGS &rest PEXS)
Documentation
Define PEG rule NAME as equivalent to PEXS.
The PEG expressions in PEXS are implicitly combined with the
sequencing and operator of PEG grammars.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/peg.el.gz
(defmacro define-peg-rule (name args &rest pexs)
"Define PEG rule NAME as equivalent to PEXS.
The PEG expressions in PEXS are implicitly combined with the
sequencing `and' operator of PEG grammars."
(declare (indent 2))
(let ((inline nil))
(while (keywordp (car pexs))
(pcase (pop pexs)
(:inline (setq inline (car pexs))))
(setq pexs (cdr pexs)))
(let ((id (peg--rule-id name))
(exp (peg-normalize `(and . ,pexs))))
`(progn
(defalias ',id
(peg--lambda ',pexs ,args
,(if inline
;; Short-circuit to peg--translate in order to skip
;; the extra failure-recording of `peg-translate-exp'.
;; It also skips the cycle detection of
;; `peg--translate-rule-body', which is not the main
;; purpose but we can live with it.
(apply #'peg--translate exp)
(peg--translate-rule-body name exp))))
(eval-and-compile
;; FIXME: We shouldn't need this any more since the info is now
;; stored in the function, but sadly we need to find a name's EXP
;; during compilation (i.e. before the `defalias' is executed)
;; as part of cycle-detection!
(put ',id 'peg--rule-definition ',exp)
,@(when inline
;; FIXME: Copied from `defsubst'.
`(;; Never native-compile defsubsts as we need the byte
;; definition in `byte-compile-unfold-bcf' to perform the
;; inlining (Bug#42664, Bug#43280, Bug#44209).
,(byte-run--set-speed id nil -1)
(put ',id 'byte-optimizer #'byte-compile-inline-expand))))))))