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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master cbd3352 55/60: Add parsec-lookahead


From: Junpeng Qiu
Subject: [elpa] master cbd3352 55/60: Add parsec-lookahead
Date: Tue, 25 Oct 2016 17:45:17 +0000 (UTC)

branch: master
commit cbd33529b83fc55967153887f273dc9c84a328c3
Author: Junpeng Qiu <address@hidden>
Commit: Junpeng Qiu <address@hidden>

    Add parsec-lookahead
---
 parsec-tests.el |   29 +++++++++++++++++++++++++++++
 parsec.el       |    7 +++++++
 2 files changed, 36 insertions(+)

diff --git a/parsec-tests.el b/parsec-tests.el
index fdf2055..e9c2672 100644
--- a/parsec-tests.el
+++ b/parsec-tests.el
@@ -229,6 +229,35 @@
                  (parsec-str "abc")))
     "abc")))
 
+(ert-deftest test-parsec-lookahead ()
+  (should
+   (equal
+    (parsec-with-input "abc"
+      (parsec-lookahead (parsec-str "abc"))
+      (point))
+    (point-min)))
+  (should
+   (equal
+    (parsec-with-input "abc"
+      (parsec-start
+       (parsec-lookahead
+        (parsec-and
+          (parsec-ch ?a)
+          (parsec-ch ?c))))
+      (point))
+    (1+ (point-min))))
+  (should
+   (equal
+    (parsec-with-input "abc"
+      (parsec-start
+       (parsec-try
+        (parsec-lookahead
+         (parsec-and
+           (parsec-ch ?a)
+           (parsec-ch ?c)))))
+      (point))
+    (point-min))))
+
 (ert-deftest test-parsec-error-handles ()
   (should
    (equal
diff --git a/parsec.el b/parsec.el
index 70209e8..f28e42c 100644
--- a/parsec.el
+++ b/parsec.el
@@ -730,6 +730,13 @@ point of your parsing program."
            (parsec-and ,parser)
          (goto-char ,orig-pt-sym)))))
 
+(defmacro parsec-lookahead (parser)
+  "Try PARSER, and pretend that no input is consumed when it succeeds."
+  (let ((orig-pt-sym (make-symbol "orig-pt")))
+    `(let ((,orig-pt-sym (point)))
+       (parsec-return ,parser
+         (goto-char ,orig-pt-sym)))))
+
 (defsubst parsec--atom-tag (name)
   (intern (format "parsec-failed-at-half-%s" name)))
 



reply via email to

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