[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/peg 47b737c 4/7: * peg.el (peg-ex-arith): Minor cleanup
From: |
Stefan Monnier |
Subject: |
[elpa] externals/peg 47b737c 4/7: * peg.el (peg-ex-arith): Minor cleanups. |
Date: |
Sun, 10 Mar 2019 17:12:09 -0400 (EDT) |
branch: externals/peg
commit 47b737c0798d247dc409417109f27b94c239f595
Author: Helmut Eller <address@hidden>
Commit: Helmut Eller <address@hidden>
* peg.el (peg-ex-arith): Minor cleanups.
---
ChangeLog | 4 ++++
peg.el | 27 ++++++++++++---------------
2 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 7abe671..5cbd460 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2009-03-06 Helmut Eller <address@hidden>
+ * peg.el (peg-ex-arith): Minor cleanups.
+
+2009-03-06 Helmut Eller <address@hidden>
+
Introduce an operator to match string literals.
* peg.el (translate =): Add = operator.
diff --git a/peg.el b/peg.el
index d51fa2d..11673e0 100644
--- a/peg.el
+++ b/peg.el
@@ -666,6 +666,10 @@ input. PATH is the list of rules that we have visited so
far."
(assert (equal (peg-parse-string ((s `(-- 1 2))) "") '(t (2 1))))
(assert (equal (peg-parse-string ((s `(-- 1 2) `(a b -- a b))) "")
'(t (2 1))))
+ (assert (equal (peg-parse-string ((s (or (and (any) s)
+ (substring [0-9]))))
+ "ab0cd1ef2gh")
+ '(t ("2"))))
(assert (equal (peg-parse-string ((s (list x y))
(x `(-- 1))
(y `(-- 2)))
@@ -744,22 +748,16 @@ input. PATH is the list of rules that we have visited so
far."
;; Parse arithmetic expressions and compute the result as side effect.
(defun peg-ex-arith ()
(peg-parse
- (expr (or (and ws sum eol)
+ (expr (or (and _ sum eol)
(and (* (not eol) (any)) eol error)))
- (sum product (* (or (and plus product `(a b -- (+ a b)))
- (and minus product `(a b -- (- a b))))))
- (product value (* (or (and times value `(a b -- (* a b)))
- (and divide value `(a b -- (/ a b))))))
+ (sum product (* (or (and "+" _ product `(a b -- (+ a b)))
+ (and "-" _ product `(a b -- (- a b))))))
+ (product value (* (or (and "*" _ value `(a b -- (* a b)))
+ (and "/" _ value `(a b -- (/ a b))))))
(value (or (and (substring number) `(string -- (string-to-number string)))
- (and open sum close)))
- (number (+ [0-9]) ws)
- (plus "+" ws)
- (minus "-" ws)
- (times "*" ws)
- (divide "/" ws)
- (open "(" ws)
- (close ")" ws)
- (ws (* (or " " "\t")))
+ (and "(" _ sum ")" _)))
+ (number (+ [0-9]) _)
+ (_ (* [" \t"]))
(eol (or "\n" "\r\n" "\r"))
(error (action (error "Parse error at: %s" (point))))))
@@ -827,7 +825,6 @@ input. PATH is the list of rules that we have visited so
far."
(lowalpha [a-z])
(upalpha [A-Z])
(digit [0-9])))
-
;; (peg-ex-uri)file:/bar/baz.html?foo=df#x
;; (peg-ex-uri)http://address@hidden:8080/bar/baz.html?x=1#foo
- [elpa] branch externals/peg created (now 081efec), Stefan Monnier, 2019/03/10
- [elpa] externals/peg a4286cb 2/7: Mention mailing list., Stefan Monnier, 2019/03/10
- [elpa] externals/peg 47b737c 4/7: * peg.el (peg-ex-arith): Minor cleanups.,
Stefan Monnier <=
- [elpa] externals/peg 3313a38 6/7: * peg.el (merge-error): Add a method for (NOT X)., Stefan Monnier, 2019/03/10
- [elpa] externals/peg cb46f6f 3/7: Introduce an operator to match string literals., Stefan Monnier, 2019/03/10
- [elpa] externals/peg 081efec 7/7: * peg.el: Cleanup whitespace., Stefan Monnier, 2019/03/10
- [elpa] externals/peg 3604f37 5/7: Add some error reporting. If a parse fails, move to the, Stefan Monnier, 2019/03/10
- [elpa] externals/peg 585f4de 1/7: Create hg repo., Stefan Monnier, 2019/03/10