[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master ba23b01 19/60: Add more APIs
From: |
Junpeng Qiu |
Subject: |
[elpa] master ba23b01 19/60: Add more APIs |
Date: |
Tue, 25 Oct 2016 17:45:13 +0000 (UTC) |
branch: master
commit ba23b01fa5752d27eea29f6621eb26d11ac1c656
Author: Junpeng Qiu <address@hidden>
Commit: Junpeng Qiu <address@hidden>
Add more APIs
---
parsec.el | 55 ++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 46 insertions(+), 9 deletions(-)
diff --git a/parsec.el b/parsec.el
index d46047b..abaa771 100644
--- a/parsec.el
+++ b/parsec.el
@@ -73,6 +73,13 @@
(parsec-stop :expected (char-to-string ch)
:found (parsec-eob-or-char-as-string)))))
+(defun parsec-any-ch ()
+ (if (not (eobp))
+ (prog1 (char-to-string (char-after))
+ (forward-char))
+ (parsec-stop :expected "any char"
+ :found (parsec-eob-or-char-as-string))))
+
(defun parsec-satisfy (pred)
(let ((next-char (char-after)))
(if (and (not (eobp))
@@ -131,6 +138,14 @@
(defalias 'parsec-return 'prog1)
+(defalias 'parsec-collect 'list)
+
+(defun parsec-collect* (&rest args)
+ (delq nil (apply #'parsec-collect args)))
+
+(defmacro parsec-collect-as-string (&rest forms)
+ `(parsec-list-to-string (parsec-collect ,@forms)))
+
(defmacro parsec-start (&rest forms)
`(catch 'parsec-failed ,@forms))
@@ -232,6 +247,24 @@
(parsec-return ,parser
,close)))
+(defmacro parsec-count (n parser)
+ (let ((res-sym (make-symbol "results")))
+ `(let (,res-sym)
+ (dotimes (_ ,n ,res-sym)
+ (push ,parser ,res-sym)))))
+
+(defmacro parsec-count-as-string (n parser)
+ `(parsec-list-to-string (parsec-count ,n ,parser)))
+
+(defmacro parsec-option (opt &rest forms)
+ `(parsec-or (parsec-and ,@forms) ,opt))
+
+(defmacro parsec-optional (&rest forms)
+ `(parsec-or (parsec-and ,@forms) nil))
+
+(defmacro parsec-optional* (&rest forms)
+ `(parsec-and (parsec-optional ,@forms) nil))
+
(defmacro parsec-query (parser &rest args)
(let ((orig-pt-sym (make-symbol "orig-pt"))
(res-sym (make-symbol "results")))
@@ -253,9 +286,9 @@
(error "Invalid query :group %s" group))))
(t res-sym)))))
-(defun parsec-just (x) (cons 'Just x))
+(defsubst parsec-just (x) (cons 'Just x))
-(defvar parsec-nothing 'Nothing)
+(defconst parsec-nothing 'Nothing)
(defun parsec-maybe-p (x)
(or (eq x parsec-nothing)
@@ -263,13 +296,17 @@
(consp x)
(eq (car x) 'Just))))
-(defmacro parsec-make-maybe (&rest forms)
- (let ((res (make-symbol "result")))
- `(let ((,res (parsec-start
- ,@forms)))
- (if (parsec-error-p ,res)
- parsec-nothing
- (parsec-just ,res)))))
+(defun parsec-from-just (x)
+ (and (consp x)
+ (eq (car x) 'Just)
+ (cdr x)))
+
+(defmacro parsec-optional-maybe (&rest forms)
+ (let ((res-sym (make-symbol "result")))
+ `(let ((,res-sym (parsec-optional ,@forms)))
+ (if ,res-sym
+ (parsec-just ,res-sym)
+ parsec-nothing))))
(defmacro parsec-with-input (input &rest parsers)
(declare (indent 1))
- [elpa] master cdb8c0d 47/60: Remove unused symbols, (continued)
- [elpa] master cdb8c0d 47/60: Remove unused symbols, Junpeng Qiu, 2016/10/25
- [elpa] master fdb3d99 44/60: Fix some code in simple-csv-parser.el, Junpeng Qiu, 2016/10/25
- [elpa] master 701964f 57/60: Prepare headers for GNU ELPA, Junpeng Qiu, 2016/10/25
- [elpa] master cbd3352 55/60: Add parsec-lookahead, Junpeng Qiu, 2016/10/25
- [elpa] master a951fbe 41/60: Unify tag names, Junpeng Qiu, 2016/10/25
- [elpa] master dfb3af0 60/60: Add 'packages/parsec/' from commit '8f0c266d8b9b0ee5fcf9b80c518644b2849ff3b3', Junpeng Qiu, 2016/10/25
- [elpa] master 6cc3100 07/60: Fix indentations, Junpeng Qiu, 2016/10/25
- [elpa] master d98e8c8 05/60: Add url-encoded string parser, Junpeng Qiu, 2016/10/25
- [elpa] master a268b9f 08/60: Add more APIs, Junpeng Qiu, 2016/10/25
- [elpa] master 13637e1 15/60: Rename parsec-do-parse to parsec-with-input, Junpeng Qiu, 2016/10/25
- [elpa] master ba23b01 19/60: Add more APIs,
Junpeng Qiu <=
- [elpa] master f3ce070 09/60: Add simple scheme parser, Junpeng Qiu, 2016/10/25
- [elpa] master 9bc1d77 28/60: Move examples to under sub-directory, Junpeng Qiu, 2016/10/25
- [elpa] master 52f1886 33/60: Update pjson, Junpeng Qiu, 2016/10/25
- [elpa] master 7e65db0 51/60: Merge pull request #1 from tarsius/master, Junpeng Qiu, 2016/10/25
- [elpa] master 311a5ca 49/60: Fix typo, Junpeng Qiu, 2016/10/25
- [elpa] master e6d5f38 46/60: Update the comment in source file, Junpeng Qiu, 2016/10/25
- [elpa] master 8c22dcb 39/60: Add :group example, Junpeng Qiu, 2016/10/25
- [elpa] master a45d8f4 03/60: Error propagation to pl-until, Junpeng Qiu, 2016/10/25