[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/parseclj b234692020 157/185: error on unmatched closing pa
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/parseclj b234692020 157/185: error on unmatched closing paren/brace |
Date: |
Tue, 28 Dec 2021 14:05:31 -0500 (EST) |
branch: elpa/parseclj
commit b2346920204322a74bbd9c8b977afa5926d76299
Author: chaos <>
Commit: chaos <>
error on unmatched closing paren/brace
---
parseclj-parser.el | 67 ++++++++++++++++++++++++++++-----------------------
test/parseclj-test.el | 30 ++++++++++++++++++++++-
2 files changed, 66 insertions(+), 31 deletions(-)
diff --git a/parseclj-parser.el b/parseclj-parser.el
index d0e5d24a21..1ae84fbed0 100644
--- a/parseclj-parser.el
+++ b/parseclj-parser.el
@@ -71,36 +71,43 @@ OPTIONS is an association list. This list is also passed
down to the
REDUCE-BRANCH function. See `parseclj-parser' for more information on
available options."
(let ((opening-token-type (parseclj--find-opening-token stack closing-token))
- (fail-fast (a-get options :fail-fast t))
- (collection nil))
-
- ;; unwind the stack until opening-token-type is found, adding to collection
- (while (and stack (not (eq (parseclj-lex-token-type (car stack))
opening-token-type)))
- (push (pop stack) collection))
-
- ;; did we find the right token?
- (if (eq (parseclj-lex-token-type (car stack)) opening-token-type)
- (progn
- (when fail-fast
- ;; any unreduced tokens left: bail early
- (when-let ((token (seq-find #'parseclj-lex-token-p collection)))
- (parseclj--error "At position %s, unmatched %S"
- (a-get token :pos)
- (parseclj-lex-token-type token))))
-
- ;; all good, call the reducer so it can return an updated stack with
a
- ;; new node at the top.
- (let ((opening-token (pop stack)))
- (funcall reduce-branch stack opening-token collection options)))
-
- ;; Unwound the stack without finding a matching paren: either bail early
- ;; or return the original stack and continue parsing
- (if fail-fast
- (parseclj--error "At position %s, unmatched %S"
- (a-get closing-token :pos)
- (parseclj-lex-token-type closing-token))
-
- (reverse collection)))))
+ (fail-fast (a-get options :fail-fast t)))
+ (if (not opening-token-type)
+ (if fail-fast
+ (parseclj--error "At position %s, unmatched %S"
+ (a-get closing-token :pos)
+ (parseclj-lex-token-type closing-token))
+
+ stack)
+
+ (let ((collection nil))
+ ;; unwind the stack until opening-token-type is found, adding to
collection
+ (while (and stack (not (eq (parseclj-lex-token-type (car stack))
opening-token-type)))
+ (push (pop stack) collection))
+
+ ;; did we find the right token?
+ (if (eq (parseclj-lex-token-type (car stack)) opening-token-type)
+ (progn
+ (when fail-fast
+ ;; any unreduced tokens left: bail early
+ (when-let ((token (seq-find #'parseclj-lex-token-p collection)))
+ (parseclj--error "At position %s, unmatched %S"
+ (a-get token :pos)
+ (parseclj-lex-token-type token))))
+
+ ;; all good, call the reducer so it can return an updated stack
with a
+ ;; new node at the top.
+ (let ((opening-token (pop stack)))
+ (funcall reduce-branch stack opening-token collection options)))
+
+ ;; Unwound the stack without finding a matching paren: either bail
early
+ ;; or return the original stack and continue parsing
+ (if fail-fast
+ (parseclj--error "At position %s, unmatched %S"
+ (a-get closing-token :pos)
+ (parseclj-lex-token-type closing-token))
+
+ (reverse collection)))))))
(defun parseclj--take-value (stack value-p)
"Scan STACK until a value is found.
diff --git a/test/parseclj-test.el b/test/parseclj-test.el
index a60ad9407a..a2c92e5fc2 100644
--- a/test/parseclj-test.el
+++ b/test/parseclj-test.el
@@ -93,7 +93,20 @@
(condition-case errdata
(parseclj-parse-clojure "(1 [2 {3 ( 4}])")
(parseclj-parser-error (cadr errdata)))
- "At position 10, unmatched :lparen")))
+ "At position 10, unmatched :lparen"))
+
+ (should (equal
+ (condition-case errdata
+ (parseclj-parse-clojure "{:a 1}}")
+ (parseclj-parser-error (cadr errdata)))
+ "At position 7, unmatched :rbrace"))
+
+ (should (equal
+ (condition-case errdata
+ (parseclj-parse-clojure "'(1))")
+ (parseclj-parser-error (cadr errdata)))
+ "At position 5, unmatched :rparen"))
+ )
(ert-deftest parseclj-parse-clojure-not-fail-fast-test ()
(should (equal (parseclj-parse-clojure "(1 [2 {3 ( 4}])" :fail-fast nil)
@@ -117,6 +130,21 @@
((:token-type . :lparen) (:form . "(") (:pos . 10))
((:node-type
. :number) (:position . 12) (:form . "4") (:value . 4))))))))))))
+ (should (equal
+ (parseclj-parse-clojure "{:a 1}}" :fail-fast nil)
+ '((:node-type . :root)
+ (:position . 1)
+ (:children ((:node-type . :map)
+ (:position . 1)
+ (:children ((:node-type . :keyword)
+ (:position . 2)
+ (:form . ":a")
+ (:value . :a))
+ ((:node-type . :number)
+ (:position . 5)
+ (:form . "1")
+ (:value . 1))))))))
+
;; TODO: uneven map forms
)
- [nongnu] elpa/parseclj 70804992ee 122/185: Merge pull request #14 from lambdaisland/parseclj-lex-symbol-fix, (continued)
- [nongnu] elpa/parseclj 70804992ee 122/185: Merge pull request #14 from lambdaisland/parseclj-lex-symbol-fix, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 19ca5f5bd0 121/185: Stick to the previous Travis Trusty image, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj b2550e6456 133/185: Add docstring for `parseclj-lex--string-value`, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 13059d8529 138/185: Minor checkdoc fixes, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 49c715ed22 148/185: For prefix-2 elements: pass children to reduce in right order, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj dc0d165b0a 152/185: Merge pull request #23 from clojure-emacs/read-one, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 62c9bf9126 177/185: Remove the last remains of a.el, restructure requires, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 517a371616 166/185: Use map-elt instead of parseclj-alist-get, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj ba04dbe334 171/185: Remove remaining a-list call, move a.el to be test-only, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 48abe456c6 155/185: Update the installation instructions, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj b234692020 157/185: error on unmatched closing paren/brace,
ELPA Syncer <=
- [nongnu] elpa/parseclj 1bb3800f8f 162/185: Update CHANGELOG, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj fcebf65075 180/185: Provide parseclj-alist-merge for older Emacsen, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj eff9411268 161/185: Merge pull request #26 from ikappaki/master, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 689ebddbdd 158/185: Add support for shebang and symbolic values, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 1e46607912 015/185: Split files into packages, More test setup, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj a9dba19760 086/185: Clean up node and token types, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 9480ae09b3 068/185: push is destructive, in this case cons will do, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj f395b9cbcc 097/185: Move `parseclj--leaf-token-value` to `parseedn` module, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 91dd43667c 110/185: Fix `parseclj-ast--reduce-branch` for tags., ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 9a586f267d 103/185: Remove `parseedn` requirement from `parseclj`, ELPA Syncer, 2021/12/28