[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/parseclj 22f2eb106f 028/185: Support \uxxxx and \oxxx esca
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/parseclj 22f2eb106f 028/185: Support \uxxxx and \oxxx escape codes in strings |
Date: |
Tue, 28 Dec 2021 14:05:11 -0500 (EST) |
branch: elpa/parseclj
commit 22f2eb106fd37272b64c4bfde6c388d308358463
Author: Arne Brasseur <arne@arnebrasseur.net>
Commit: Arne Brasseur <arne@arnebrasseur.net>
Support \uxxxx and \oxxx escape codes in strings
---
clj-lex-test.el | 7 ++++++-
clj-parse-test.el | 7 ++++++-
clj-parse.el | 42 ++++++++++++++++++++++++++----------------
3 files changed, 38 insertions(+), 18 deletions(-)
diff --git a/clj-lex-test.el b/clj-lex-test.el
index eeabcdc4db..426698303a 100644
--- a/clj-lex-test.el
+++ b/clj-lex-test.el
@@ -89,7 +89,12 @@
(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)))))
+ (should (equal (clj-lex-next) (clj-lex-token :character "\\o170" 7))))
+
+ (with-temp-buffer
+ (insert "\"\\u0078\\o170\"")
+ (goto-char 1)
+ (should (equal (clj-lex-next) (clj-lex-token :string "\"\\u0078\\o170\""
1)))))
(ert-deftest clj-lex-test-at-number? ()
(dolist (str '("123" ".9" "+1" "0" "-456"))
diff --git a/clj-parse-test.el b/clj-parse-test.el
index 2c003cb17b..fae8cc03e5 100644
--- a/clj-parse-test.el
+++ b/clj-parse-test.el
@@ -64,7 +64,12 @@
(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))))))
+ (should (equal (clj-parse) '((?\n ?\r ?\ ?\t ?a ?b ?c ?x ?y)))))
+
+ (with-temp-buffer
+ (insert "\"\\u0078 \\o171\"")
+ (goto-char 1)
+ (should (equal (clj-parse) '("x y")))))
(provide 'clj-parse-test)
diff --git a/clj-parse.el b/clj-parse.el
index 610a98eac0..004901090b 100644
--- a/clj-parse.el
+++ b/clj-parse.el
@@ -39,23 +39,33 @@
:character)
"Tokens that represent leaf nodes in the AST.")
-;; Java/JavaScript strings support other escape codes like "\u0111", but
-;; these are the only ones mentioned in the EDN spec.
-;; Although of course for bare characters
+;; The EDN spec is not clear about wether \u0123 and \o012 are supported in
+;; strings. They are described as character literals, but not as string escape
+;; codes. In practice all implementations support them (mostly with broken
+;; surrogate pair support), so we do the same. Sorry, emoji 🙁.
+;;
+;; Note that this is kind of broken, we don't correctly detect if \u or \o
forms
+;; don't have the right forms.
(defun clj-parse-string (s)
- (replace-regexp-in-string "\\\\[tbnrf'\"\\]"
- (lambda (x)
- (cl-case (elt x 1)
- (?t "\t")
- (?f "\f")
- (?\" "\"")
- (?r "\r")
- (?n "\n")
- (?\\ "\\\\")
- (t (substring x 1 2))))
- (substring s 1 -1)))
-
-
+ (replace-regexp-in-string
+ "\\\\o[0-8]\\{3\\}"
+ (lambda (x)
+ (make-string 1 (string-to-number (substring x 2) 8) ))
+ (replace-regexp-in-string
+ "\\\\u[0-9a-fA-F]\\{4\\}"
+ (lambda (x)
+ (make-string 1 (string-to-number (substring x 2) 16)))
+ (replace-regexp-in-string "\\\\[tbnrf'\"\\]"
+ (lambda (x)
+ (cl-case (elt x 1)
+ (?t "\t")
+ (?f "\f")
+ (?\" "\"")
+ (?r "\r")
+ (?n "\n")
+ (?\\ "\\\\")
+ (t (substring x 1))))
+ (substring s 1 -1)))))
(defun clj-parse-character (c)
(let* ((form (cdr (assq 'form token)))
- [nongnu] branch elpa/parseclj created (now a8c4cf30fb), ELPA Syncer, 2021/12/28
- [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 <=
- [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, 2021/12/28
- [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