emacs-elpa-diffs
[Top][All Lists]
Advanced

[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
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]