[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/parseclj da1929be0b 031/185: Add vector support
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/parseclj da1929be0b 031/185: Add vector support |
Date: |
Tue, 28 Dec 2021 14:05:11 -0500 (EST) |
branch: elpa/parseclj
commit da1929be0bf6b1ad4ed663a9957feb4dddf20663
Author: Arne Brasseur <arne@arnebrasseur.net>
Commit: Arne Brasseur <arne@arnebrasseur.net>
Add vector support
---
clj-lex-test.el | 9 ++++++++-
clj-lex.el | 8 ++++++++
clj-parse-test.el | 7 ++++++-
clj-parse.el | 15 +++++++++------
4 files changed, 31 insertions(+), 8 deletions(-)
diff --git a/clj-lex-test.el b/clj-lex-test.el
index baea9dcd0f..8da315ca50 100644
--- a/clj-lex-test.el
+++ b/clj-lex-test.el
@@ -109,7 +109,14 @@
(with-temp-buffer
(insert ":::hello-world")
(goto-char 1)
- (should (equal (clj-lex-next) (clj-lex-token :lex-error ":::" 1
'error-type :invalid-keyword)))))
+ (should (equal (clj-lex-next) (clj-lex-token :lex-error ":::" 1
'error-type :invalid-keyword))))
+
+ (with-temp-buffer
+ (insert "[123]")
+ (goto-char 1)
+ (should (equal (clj-lex-next) (clj-lex-token :lbracket "[" 1)))
+ (should (equal (clj-lex-next) (clj-lex-token :number "123" 2)))
+ (should (equal (clj-lex-next) (clj-lex-token :rbracket "]" 5)))))
(ert-deftest clj-lex-test-at-number? ()
(dolist (str '("123" ".9" "+1" "0" "-456"))
diff --git a/clj-lex.el b/clj-lex.el
index 94874aa6d0..377e8c766b 100644
--- a/clj-lex.el
+++ b/clj-lex.el
@@ -177,6 +177,14 @@
(right-char)
(clj-lex-token :rparen ")" pos))
+ ((equal char ?\[)
+ (right-char)
+ (clj-lex-token :lbracket "[" pos))
+
+ ((equal char ?\])
+ (right-char)
+ (clj-lex-token :rbracket "]" pos))
+
((clj-lex-at-number?)
(clj-lex-number))
diff --git a/clj-parse-test.el b/clj-parse-test.el
index d026bbc172..8f2869cd06 100644
--- a/clj-parse-test.el
+++ b/clj-parse-test.el
@@ -79,7 +79,12 @@
(with-temp-buffer
(insert ":foo-bar")
(goto-char 1)
- (should (equal (clj-parse) '(:foo-bar)))))
+ (should (equal (clj-parse) '(:foo-bar))))
+
+ (with-temp-buffer
+ (insert "[123]")
+ (goto-char 1)
+ (should (equal (clj-parse) '([123])))))
(provide 'clj-parse-test)
diff --git a/clj-parse.el b/clj-parse.el
index 6cf49aac9e..7a12152357 100644
--- a/clj-parse.el
+++ b/clj-parse.el
@@ -97,7 +97,8 @@
(cl-case type
(:whitespace :ws)
(:number coll)
- (:list (-butlast (cdr coll))))
+ (:list (-butlast (cdr coll)))
+ (:vector (apply #'vector (-butlast (cdr coll)))))
stack))
;; TODO move this to clj-lex
@@ -105,15 +106,15 @@
(and (listp token)
(cdr (assq 'type token))))
-(defun clj-parse--reduce-list (stack reducN)
+(defun clj-parse--reduce-coll (stack open-token coll-type reducN)
(let ((coll nil))
(while (and stack
- (not (eq (clj-parse--token-type (car stack)) :lparen)))
+ (not (eq (clj-parse--token-type (car stack)) open-token)))
(push (pop stack) coll))
- (if (eq (clj-parse--token-type (car stack)) :lparen)
+ (if (eq (clj-parse--token-type (car stack)) open-token)
(progn
(push (pop stack) coll)
- (funcall reduceN stack :list coll))
+ (funcall reduceN stack coll-type coll))
;; Unwound the stack without finding a matching paren: return the
original stack
(reverse list))))
@@ -132,7 +133,9 @@
(cons token stack)))
(cl-case (clj-parse--token-type (car stack))
- (:rparen (setf stack (clj-parse--reduce-list stack reduceN))))
+ (:rparen (setf stack (clj-parse--reduce-coll stack :lparen :list
reduceN)))
+ (:rbracket (setf stack (clj-parse--reduce-coll stack :lbracket :vector
reduceN))))
+
(setq token (clj-lex-next)))
- [nongnu] elpa/parseclj 811f35e05a 117/185: Loops reduction over the first 2 elements of the stack, (continued)
- [nongnu] elpa/parseclj 811f35e05a 117/185: Loops reduction over the first 2 elements of the stack, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 5b4b222b4f 124/185: Return error token when there's invalid input in `parseclj-lex-next`, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj b26fadbc05 128/185: Get rid of `parseclj-lex-error-token` side-effect, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 2ffadc6239 134/185: Mark OPTIONS as unused in `parseedn-reduce-leaf`, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 45cd754c32 140/185: Remove parseedn files, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 3e48aa7b40 141/185: Remove mentions to parseedn in README.md, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj c62a11884d 165/185: First pass in inlining the necessary bits from a.el, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 8a361f4c05 175/185: Merge pull request #32 from dawranliou/dawranliou/remove-a-el-part-3, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 6f9ab8f89c 181/185: Replace `cl-case` calls with `cond`, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 1dc147f552 027/185: Support character literals, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj da1929be0b 031/185: Add vector support,
ELPA Syncer <=
- [nongnu] elpa/parseclj 1c8f833b4c 176/185: Release 1.0.2, ELPA Syncer, 2021/12/28