[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/peg f48b9066ef 1/2: * peg.el (peg--translate) <with>: N
From: |
Stefan Monnier |
Subject: |
[elpa] externals/peg f48b9066ef 1/2: * peg.el (peg--translate) <with>: New PEX form |
Date: |
Sun, 11 Dec 2022 11:55:07 -0500 (EST) |
branch: externals/peg
commit f48b9066ef02871cc15be0f6743abe46f45ba079
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
* peg.el (peg--translate) <with>: New PEX form
---
peg.el | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/peg.el b/peg.el
index d7247bf1b6..0d0cab8ca1 100644
--- a/peg.el
+++ b/peg.el
@@ -68,6 +68,7 @@
;; Character classes [ascii cntrl]
;; Boolean-guard (guard EXP)
;; Syntax-Class (syntax-class NAME)
+;; Local definitions (with RULES PEX...)
;; and
;; Empty-string (null) ε
;; Beginning-of-Buffer (bob)
@@ -219,6 +220,7 @@
;; Since 1.0.1:
;; - Use OClosures to represent PEG rules when available, and let cl-print
;; display their source code.
+;; - New PEX form (with RULES PEX...).
;; Version 1.0:
;; - New official entry points `peg` and `peg-run`.
@@ -260,8 +262,6 @@ EXPS is a list of rules/expressions that failed.")
(prin1 (peg-function--pexs peg) stream)
(princ ">" stream)))
-;; Sometimes (with-peg-rules ... (peg-run (peg ...))) is too
-;; longwinded for the task at hand, so `peg-parse' comes in handy.
(defmacro peg--lambda (pexs args &rest body)
(declare (indent 2)
(debug (&define form lambda-list def-body)))
@@ -269,6 +269,8 @@ EXPS is a list of rules/expressions that failed.")
`(oclosure-lambda (peg-function (pexs ,pexs)) ,args . ,body)
`(lambda ,args . ,body)))
+;; Sometimes (with-peg-rules ... (peg-run (peg ...))) is too
+;; longwinded for the task at hand, so `peg-parse' comes in handy.
(defmacro peg-parse (&rest pexs)
"Match PEXS at point.
PEXS is a sequence of PEG expressions, implicitly combined with `and'.
@@ -394,7 +396,7 @@ of PEG expressions, implicitly combined with `and'."
;; With `peg-function' objects, we can recover the PEG from which it was
;; defined, but this info is not yet available at compile-time. :-(
;;(let ((id (peg--rule-id name)))
- ;; (peg-function--peg (symbol-function id)))
+ ;; (peg-function--pexs (symbol-function id)))
(get (peg--rule-id name) 'peg--rule-definition)))
(defun peg--rule-id (name)
@@ -632,6 +634,9 @@ of PEG expressions, implicitly combined with `and'."
(,@(peg--choicepoint-restore cp)
,(peg-translate-exp e2)))))
+(cl-defmethod peg--translate ((_ (eql with)) rules &rest exps)
+ `(with-peg-rules ,rules ,(peg--translate `(and . ,exps))))
+
(cl-defmethod peg--translate ((_ (eql guard)) exp) exp)
(defvar peg-syntax-classes