[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/parseclj 1eef0b62c8 034/185: Support #_discard forms
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/parseclj 1eef0b62c8 034/185: Support #_discard forms |
Date: |
Tue, 28 Dec 2021 14:05:11 -0500 (EST) |
branch: elpa/parseclj
commit 1eef0b62c85a95a175f98468b1146ca2819d9cee
Author: Arne Brasseur <arne@arnebrasseur.net>
Commit: Arne Brasseur <arne@arnebrasseur.net>
Support #_discard forms
---
clj-lex-test.el | 21 ++++++++++++++++++++-
clj-lex.el | 15 ++++++++++++++-
clj-parse-test.el | 7 ++++++-
clj-parse.el | 45 ++++++++++++++++++++++++++-------------------
4 files changed, 66 insertions(+), 22 deletions(-)
diff --git a/clj-lex-test.el b/clj-lex-test.el
index 99cea11c28..405420afcb 100644
--- a/clj-lex-test.el
+++ b/clj-lex-test.el
@@ -132,7 +132,26 @@
(goto-char 1)
(should (equal (clj-lex-next) (clj-lex-token :set "#{" 1)))
(should (equal (clj-lex-next) (clj-lex-token :keyword ":x" 3)))
- (should (equal (clj-lex-next) (clj-lex-token :rbrace "}" 5)))))
+ (should (equal (clj-lex-next) (clj-lex-token :rbrace "}" 5))))
+
+ (with-temp-buffer
+ (insert "(10 #_11 12 #_#_ 13 14)")
+ (goto-char 1)
+ (should (equal (clj-lex-next) (clj-lex-token :lparen "(" 1)))
+ (should (equal (clj-lex-next) (clj-lex-token :number "10" 2)))
+ (should (equal (clj-lex-next) (clj-lex-token :whitespace " " 4)))
+ (should (equal (clj-lex-next) (clj-lex-token :discard "#_" 5)))
+ (should (equal (clj-lex-next) (clj-lex-token :number "11" 7)))
+ (should (equal (clj-lex-next) (clj-lex-token :whitespace " " 9)))
+ (should (equal (clj-lex-next) (clj-lex-token :number "12" 10)))
+ (should (equal (clj-lex-next) (clj-lex-token :whitespace " " 12)))
+ (should (equal (clj-lex-next) (clj-lex-token :discard "#_" 13)))
+ (should (equal (clj-lex-next) (clj-lex-token :discard "#_" 15)))
+ (should (equal (clj-lex-next) (clj-lex-token :whitespace " " 17)))
+ (should (equal (clj-lex-next) (clj-lex-token :number "13" 18)))
+ (should (equal (clj-lex-next) (clj-lex-token :whitespace " " 20)))
+ (should (equal (clj-lex-next) (clj-lex-token :number "14" 21)))
+ (should (equal (clj-lex-next) (clj-lex-token :rparen ")" 23)))))
(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 4901667d3f..af6581ed01 100644
--- a/clj-lex.el
+++ b/clj-lex.el
@@ -30,6 +30,16 @@
(cons (car pair) (cadr pair)))
(-partition 2 args))))
+(defun clj-lex-token-type (token)
+ (and (listp token)
+ (cdr (assq 'type token))))
+
+(defun clj-lex-token? (token)
+ (and (listp token)
+ (consp (car token))
+ (eq 'type (caar token))
+ (not (listp (cdar token)))))
+
(defun clj-lex-at-whitespace? ()
(let ((char (char-after (point))))
(or (equal char ?\ )
@@ -214,7 +224,10 @@
(cl-case char
(?{
(right-char)
- (clj-lex-token :set "#{" pos)))))
+ (clj-lex-token :set "#{" pos))
+ (?_
+ (right-char)
+ (clj-lex-token :discard "#_" pos)))))
":("))))
diff --git a/clj-parse-test.el b/clj-parse-test.el
index ef06cb6d04..90e385fad7 100644
--- a/clj-parse-test.el
+++ b/clj-parse-test.el
@@ -94,7 +94,12 @@
(with-temp-buffer
(insert "#{:x}")
(goto-char 1)
- (should (equal (clj-parse) '((:x))))))
+ (should (equal (clj-parse) '((:x)))))
+
+ (with-temp-buffer
+ (insert "(10 #_11 12 #_#_ 13 14)")
+ (goto-char 1)
+ (should (equal (clj-parse) '((10 12))))))
(provide 'clj-parse-test)
diff --git a/clj-parse.el b/clj-parse.el
index 85cfd7db66..37c724af0c 100644
--- a/clj-parse.el
+++ b/clj-parse.el
@@ -93,29 +93,31 @@
(:character (cons (clj-parse-character (cdr (assq 'form token))) stack))))
(defun clj-parse-edn-reduceN (stack type coll)
- (cons
- (cl-case type
- (:whitespace :ws)
- (:number coll)
- (:list (-butlast (cdr coll)))
- (:set (-butlast (cdr coll)))
- (:vector (apply #'vector (-butlast (cdr coll))))
- (:map (mapcar (lambda (pair)
- (cons (car pair) (cadr pair)))
- (-partition 2 (-butlast (cdr coll))))))
- stack))
+ (if (eq :discard type)
+ stack
+ (cons
+ (cl-case type
+ (:whitespace :ws)
+ (:number coll)
+ (:list (-butlast (cdr coll)))
+ (:set (-butlast (cdr coll)))
+ (:vector (apply #'vector (-butlast (cdr coll))))
+ (:map (mapcar (lambda (pair)
+ (cons (car pair) (cadr pair)))
+ (-partition 2 (-butlast (cdr coll))))))
+ stack)))
;; TODO move this to clj-lex
-(defun clj-parse--token-type (token)
+(defun clj-lex-token-type (token)
(and (listp token)
(cdr (assq 'type token))))
(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)) open-token)))
+ (not (eq (clj-lex-token-type (car stack)) open-token)))
(push (pop stack) coll))
- (if (eq (clj-parse--token-type (car stack)) open-token)
+ (if (eq (clj-lex-token-type (car stack)) open-token)
(progn
(push (pop stack) coll)
(funcall reduceN stack coll-type coll))
@@ -126,30 +128,35 @@
(let ((stack nil)
(token (clj-lex-next)))
- (while (not (eq (clj-parse--token-type token) :eof))
+ (while (not (eq (clj-lex-token-type token) :eof))
(message "STACK: %S" stack)
(message "TOKEN: %S\n" token)
(setf stack
- (if (member (clj-parse--token-type token)
+ (if (member (clj-lex-token-type token)
clj-parse--leaf-tokens)
(funcall reduce1 stack token)
(cons token stack)))
- (cl-case (clj-parse--token-type (car stack))
+ ;; Reduce based on the top item on the stack (collections)
+ (cl-case (clj-lex-token-type (car stack))
(:rparen (setf stack (clj-parse--reduce-coll stack :lparen :list
reduceN)))
(:rbracket (setf stack (clj-parse--reduce-coll stack :lbracket :vector
reduceN)))
(:rbrace
(let ((open-token (-find (lambda (token)
- (member (clj-parse--token-type token)
'(:lbrace :set)))
+ (member (clj-lex-token-type token)
'(:lbrace :set)))
stack)))
- (cl-case (clj-parse--token-type open-token)
+ (cl-case (clj-lex-token-type open-token)
(:lbrace
(setf stack (clj-parse--reduce-coll stack :lbrace :map reduceN)))
(:set
(setf stack (clj-parse--reduce-coll stack :set :set
reduceN)))))))
+ ;; Reduce based on top two items on the stack
+ (if (not (clj-lex-token? (car stack))) ;; top is fully reduced
+ (cl-case (clj-lex-token-type (second stack))
+ (:discard (setf stack (funcall reduceN (cddr stack) :discard
(-take 2 stack))))))
(setq token (clj-lex-next)))
- [nongnu] elpa/parseclj 2d10ef3742 002/185: Travis CI / test setup, (continued)
- [nongnu] elpa/parseclj 2d10ef3742 002/185: Travis CI / test setup, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 01608b7537 007/185: Seriously thinking of sticking to Emacs 25. This is getting ridiculous., ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj ee71cb8afe 005/185: Try again for the Travis build, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 4df6ae1bc7 012/185: Travis: only install the necessary ppa/package for each matrix line, 2nd attempt, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj e179a11ec4 016/185: More of trying to appease the mighty gods of Travis, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj d5167bf4ad 021/185: Test/lint stuff, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 22f2eb106f 028/185: Support \uxxxx and \oxxx escape codes in strings, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 343052c01a 014/185: Add linting to the build, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 07739abe2c 030/185: support keywords, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj ced0b91c08 029/185: "Support" namespaces symbols, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 1eef0b62c8 034/185: Support #_discard forms,
ELPA Syncer <=
- [nongnu] elpa/parseclj 0974b56833 035/185: Stick to non CL functions, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj f8822bb43c 040/185: Add support for tags in lexer, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 43f59dcb91 043/185: Avoid dropping whitespaces, handling them while reducing, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 7733985037 047/185: DESIGN.md-related adjustments, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj c906de33a1 048/185: Rewrite all tests, and add new tests for the AST "printer", ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 697618dbb1 049/185: Merge pull request #1 from volrath/master, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj e7686c49ed 052/185: Greater parity with edn.el, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 2da47798d9 057/185: Enable more edn.el tests, document how time/uuid are stored, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj f6de87fbe6 067/185: Split EDN and AST handling in separate files, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj d410a1530e 096/185: Add code-checking defaults to `dir-locals.el`, ELPA Syncer, 2021/12/28