[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/parseclj 689ebddbdd 158/185: Add support for shebang and s
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/parseclj 689ebddbdd 158/185: Add support for shebang and symbolic values |
Date: |
Tue, 28 Dec 2021 14:05:32 -0500 (EST) |
branch: elpa/parseclj
commit 689ebddbdd3378f2cabee05de9cfac9dc3137c9e
Author: Arne Brasseur <arne@arnebrasseur.net>
Commit: Arne Brasseur <arne@arnebrasseur.net>
Add support for shebang and symbolic values
These are two things handled by the LispReader's dispatch of # that we
aren't
handling yet.
#!/foo/bar
##NaN ##Inf ##-Inf
---
parseclj-lex.el | 12 +++++--
test/parseclj-lex-test.el | 36 ++++++++++++++++++--
test/parseclj-test.el | 83 ++++++++++++++++++++++++++++++++++++++---------
3 files changed, 111 insertions(+), 20 deletions(-)
diff --git a/parseclj-lex.el b/parseclj-lex.el
index f3d445f48e..f7592dec0d 100644
--- a/parseclj-lex.el
+++ b/parseclj-lex.el
@@ -29,6 +29,7 @@
(defvar parseclj-lex--leaf-tokens '(:whitespace
:comment
+ :symbolic-value
:number
:nil
:true
@@ -169,8 +170,8 @@ S goes through three transformations:
(:symbol (intern (alist-get :form token)))
(:keyword (intern (alist-get :form token)))
(:string (parseclj-lex--string-value (alist-get :form token)))
- (:character (parseclj-lex--character-value (alist-get :form token)))))
-
+ (:character (parseclj-lex--character-value (alist-get :form token)))
+ (:symbolic-value (intern (substring (alist-get :form token) 2)))))
;; Stream tokenization
@@ -515,6 +516,10 @@ See `parseclj-lex-token'."
((equal char ?=)
(right-char)
(parseclj-lex-token :eval "#=" pos))
+ ((equal char ?#)
+ (right-char)
+ (let ((sym (parseclj-lex-get-symbol-at-point (point))))
+ (parseclj-lex-token :symbolic-value (concat "##" sym) pos)))
((equal char ?\")
(parseclj-lex-regex))
((equal char ?:)
@@ -529,6 +534,9 @@ See `parseclj-lex-token'."
((parseclj-lex-symbol-start-p char t)
(right-char)
(parseclj-lex-token :tag (concat "#"
(parseclj-lex-get-symbol-at-point (1+ pos))) pos))
+ ((equal char ?!) ;; shebang
+ (left-char)
+ (parseclj-lex-comment))
(t
(while (not (or (parseclj-lex-at-whitespace-p)
(parseclj-lex-at-eof-p)))
diff --git a/test/parseclj-lex-test.el b/test/parseclj-lex-test.el
index 289fa72026..e528580ea8 100644
--- a/test/parseclj-lex-test.el
+++ b/test/parseclj-lex-test.el
@@ -21,11 +21,11 @@
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
-;;; Commentary
+;;; Commentary:
;; Unit tests for the lexer
-;;; Code
+;;; Code:
(require 'ert)
(require 'parseclj-lex)
@@ -222,7 +222,37 @@
(should (equal (parseclj-lex-next) (parseclj-lex-token :number "13" 18)))
(should (equal (parseclj-lex-next) (parseclj-lex-token :whitespace " "
20)))
(should (equal (parseclj-lex-next) (parseclj-lex-token :number "14" 21)))
- (should (equal (parseclj-lex-next) (parseclj-lex-token :rparen ")" 23)))))
+ (should (equal (parseclj-lex-next) (parseclj-lex-token :rparen ")" 23))))
+
+ (with-temp-buffer
+ (insert "#!/usr/bin/clojure")
+ (goto-char 1)
+ (should (equal (parseclj-lex-next) (parseclj-lex-token :comment
"#!/usr/bin/clojure" 1))))
+
+ (with-temp-buffer
+ (insert "##-Inf ##Inf ##NaN")
+ (goto-char 1)
+ (should (equal
+ (list (parseclj-lex-next)
+ (parseclj-lex-next)
+ (parseclj-lex-next)
+ (parseclj-lex-next)
+ (parseclj-lex-next))
+ '(((:token-type . :symbolic-value)
+ (:form . "##-Inf")
+ (:pos . 1))
+ ((:token-type . :whitespace)
+ (:form . " ")
+ (:pos . 7))
+ ((:token-type . :symbolic-value)
+ (:form . "##Inf")
+ (:pos . 8))
+ ((:token-type . :whitespace)
+ (:form . " ")
+ (:pos . 13))
+ ((:token-type . :symbolic-value)
+ (:form . "##NaN")
+ (:pos . 14)))))))
(ert-deftest parseclj-lex-test-at-number-p ()
(dolist (str '("123" ".9" "+1" "0" "-456"))
diff --git a/test/parseclj-test.el b/test/parseclj-test.el
index a60ad9407a..ad424030be 100644
--- a/test/parseclj-test.el
+++ b/test/parseclj-test.el
@@ -320,21 +320,74 @@
top-value)))
(ert-deftest parseclj---read-one-test ()
- (equal (parseclj-parse-clojure "(+ 1 1) foo bar" :read-one t)
- '((:node-type . :list)
- (:position . 1)
- (:children ((:node-type . :symbol)
- (:position . 2)
- (:form . "+")
- (:value . +))
- ((:node-type . :number)
- (:position . 4)
- (:form . "1")
- (:value . 1))
- ((:node-type . :number)
- (:position . 6)
- (:form . "1")
- (:value . 1))))))
+ (should (equal (parseclj-parse-clojure "(+ 1 1) foo bar" :read-one t)
+ '((:node-type . :list)
+ (:position . 1)
+ (:children ((:node-type . :symbol)
+ (:position . 2)
+ (:form . "+")
+ (:value . +))
+ ((:node-type . :number)
+ (:position . 4)
+ (:form . "1")
+ (:value . 1))
+ ((:node-type . :number)
+ (:position . 6)
+ (:form . "1")
+ (:value . 1)))))))
+
+(ert-deftest parseclj---shebang-test ()
+ (should
+ (equal (parseclj-parse-clojure "#!/bin/sh\n(+ 1 1)" :lexical-preservation t)
+ '((:node-type . :root)
+ (:lexical-preservation . t)
+ (:position . 1)
+ (:children ((:node-type . :comment)
+ (:position . 1)
+ (:form . "#!/bin/sh
+"))
+ ((:node-type . :list)
+ (:lexical-preservation . t)
+ (:position . 11)
+ (:children ((:node-type . :symbol)
+ (:position . 12)
+ (:form . "+")
+ (:value . +))
+ ((:node-type . :whitespace)
+ (:position . 13)
+ (:form . " "))
+ ((:node-type . :number)
+ (:position . 14)
+ (:form . "1")
+ (:value . 1))
+ ((:node-type . :whitespace)
+ (:position . 15)
+ (:form . " "))
+ ((:node-type . :number)
+ (:position . 16)
+ (:form . "1")
+ (:value . 1)))))))))
+
+
+(ert-deftest parseclj---symbolic-value-test ()
+ (should (equal (parseclj-parse-clojure "(* ##NaN 1)")
+ '((:node-type . :root)
+ (:position . 1)
+ (:children ((:node-type . :list)
+ (:position . 1)
+ (:children ((:node-type . :symbol)
+ (:position . 2)
+ (:form . "*")
+ (:value . *))
+ ((:node-type . :symbolic-value)
+ (:position . 4)
+ (:form . "##NaN")
+ (:value . NaN))
+ ((:node-type . :number)
+ (:position . 10)
+ (:form . "1")
+ (:value . 1)))))))))
+
(provide 'parseclj-test)
- [nongnu] elpa/parseclj 49c715ed22 148/185: For prefix-2 elements: pass children to reduce in right order, (continued)
- [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, 2021/12/28
- [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 <=
- [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
- [nongnu] elpa/parseclj e65eb085ad 114/185: Remove duplicated test, ELPA Syncer, 2021/12/28
- [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