[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/parseclj 1dc147f552 027/185: Support character literals
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/parseclj 1dc147f552 027/185: Support character literals |
Date: |
Tue, 28 Dec 2021 14:05:11 -0500 (EST) |
branch: elpa/parseclj
commit 1dc147f5523237aca5c365bc6b10fd08a1864674
Author: Arne Brasseur <arne@arnebrasseur.net>
Commit: Arne Brasseur <arne@arnebrasseur.net>
Support character literals
---
clj-lex-test.el | 19 +++++++++++++++++--
clj-lex.el | 8 ++++++++
clj-parse-test.el | 10 +++++-----
clj-parse.el | 20 +++++++++++++++++---
4 files changed, 47 insertions(+), 10 deletions(-)
diff --git a/clj-lex-test.el b/clj-lex-test.el
index 89035d54cd..eeabcdc4db 100644
--- a/clj-lex-test.el
+++ b/clj-lex-test.el
@@ -72,9 +72,24 @@
(should (equal (clj-lex-next) (clj-lex-token :character "\\tab" 22)))
(should (equal (clj-lex-next) (clj-lex-token :character "\\a" 26)))
(should (equal (clj-lex-next) (clj-lex-token :character "\\b" 28)))
- (should (equal (clj-lex-next) (clj-lex-token :character "\\c" 30)))
+ (should (equal (clj-lex-next) (clj-lex-token :character "\\c" 30))))
- ))
+ (with-temp-buffer
+ (insert "\\newline\\return\\space\\tab\\a\\b\\c")
+ (goto-char 1)
+ (should (equal (clj-lex-next) (clj-lex-token :character "\\newline" 1)))
+ (should (equal (clj-lex-next) (clj-lex-token :character "\\return" 9)))
+ (should (equal (clj-lex-next) (clj-lex-token :character "\\space" 16)))
+ (should (equal (clj-lex-next) (clj-lex-token :character "\\tab" 22)))
+ (should (equal (clj-lex-next) (clj-lex-token :character "\\a" 26)))
+ (should (equal (clj-lex-next) (clj-lex-token :character "\\b" 28)))
+ (should (equal (clj-lex-next) (clj-lex-token :character "\\c" 30))))
+
+ (with-temp-buffer
+ (insert "\\u0078\\o170")
+ (goto-char 1)
+ (should (equal (clj-lex-next) (clj-lex-token :character "\\u0078" 1)))
+ (should (equal (clj-lex-next) (clj-lex-token :character "\\o170" 7)))))
(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 38f1b7d00c..9b20df9bae 100644
--- a/clj-lex.el
+++ b/clj-lex.el
@@ -134,6 +134,14 @@
(right-char 7)
(clj-lex-token :character (buffer-substring-no-properties pos (point))
pos))
+ ((equal (char-after (point)) ?u)
+ (right-char 5)
+ (clj-lex-token :character (buffer-substring-no-properties pos (point))
pos))
+
+ ((equal (char-after (point)) ?o)
+ (right-char 4)
+ (clj-lex-token :character (buffer-substring-no-properties pos (point))
pos))
+
(t
(right-char)
(clj-lex-token :character (buffer-substring-no-properties pos (point))
pos)))))
diff --git a/clj-parse-test.el b/clj-parse-test.el
index 0f93277997..2c003cb17b 100644
--- a/clj-parse-test.el
+++ b/clj-parse-test.el
@@ -59,13 +59,13 @@
(with-temp-buffer
(insert "(\"---\\f---\\\"-'\\'-\\\\-\\r\\n\")")
(goto-char 1)
- (should (equal (clj-parse) '(("---\f---\"-''-\\-\r\n"))))))
+ (should (equal (clj-parse) '(("---\f---\"-''-\\-\r\n")))))
-;; (ert-deftest clj-parse-test--reduce-list ()
-;; (clj-parse-test--reduce-list ))
+ (with-temp-buffer
+ (insert "(\\newline \\return \\space \\tab \\a \\b \\c \\u0078 \\o171)")
+ (goto-char 1)
+ (should (equal (clj-parse) '((?\n ?\r ?\ ?\t ?a ?b ?c ?x ?y))))))
(provide 'clj-parse-test)
;;; clj-parse-test.el ends here
-
-"hello"
diff --git a/clj-parse.el b/clj-parse.el
index 48efd43eff..610a98eac0 100644
--- a/clj-parse.el
+++ b/clj-parse.el
@@ -35,7 +35,8 @@
:true
:false
:symbol
- :string)
+ :string
+ :character)
"Tokens that represent leaf nodes in the AST.")
;; Java/JavaScript strings support other escape codes like "\u0111", but
@@ -54,7 +55,19 @@
(t (substring x 1 2))))
(substring s 1 -1)))
-(replace-regexp-in-string "x" "\\\\" "x")
+
+
+(defun clj-parse-character (c)
+ (let* ((form (cdr (assq 'form token)))
+ (first-char (elt form 1)))
+ (cond
+ ((equal form "\\newline") ?\n)
+ ((equal form "\\return") ?\r)
+ ((equal form "\\space") ?\ )
+ ((equal form "\\tab") ?\t)
+ ((eq first-char ?u) (string-to-number (substring form 2) 16))
+ ((eq first-char ?o) (string-to-number (substring form 2) 8))
+ (t first-char))))
(defun clj-parse-edn-reduce1 (stack token)
(cl-case (cdr (assq 'type token))
@@ -64,7 +77,8 @@
(:true (cons t stack))
(:false (cons nil stack))
(:symbol (cons (intern (cdr (assq 'form token))) stack))
- (:string (cons (clj-parse-string (cdr (assq 'form token))) stack))))
+ (:string (cons (clj-parse-string (cdr (assq 'form token))) stack))
+ (:character (cons (clj-parse-character (cdr (assq 'form token))) stack))))
(defun clj-parse-edn-reduceN (stack type coll)
(cons
- [nongnu] elpa/parseclj e65eb085ad 114/185: Remove duplicated test, (continued)
- [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
- [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 <=
- [nongnu] elpa/parseclj da1929be0b 031/185: Add vector support, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 1c8f833b4c 176/185: Release 1.0.2, ELPA Syncer, 2021/12/28