branch: elpa/parseclj
commit 879ac980a83468cebc87102e2e2ab85e0fcf4679
Author: Arne Brasseur <[email protected]>
Commit: Arne Brasseur <[email protected]>
Treat numbers with trailing symbol characters as lex errors
---
clj-lex-test.el | 12 ++++++++++++
clj-lex.el | 17 ++++++++++++++---
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/clj-lex-test.el b/clj-lex-test.el
index 30d1082625..44553571a4 100644
--- a/clj-lex-test.el
+++ b/clj-lex-test.el
@@ -38,6 +38,18 @@
(form . "123")
(pos . 1)))))
+ (with-temp-buffer
+ (insert "123e34M")
+ (goto-char 1)
+ (should (equal (clj-lex-next) '((type . :number)
+ (form . "123e34M")
+ (pos . 1)))))
+
+ (with-temp-buffer
+ (insert "123x")
+ (goto-char 1)
+ (should (equal (clj-lex-next) (clj-lex-token :lex-error "123x" 1
'error-type :invalid-number-format))))
+
(with-temp-buffer
(insert " \t \n")
(goto-char 1)
diff --git a/clj-lex.el b/clj-lex.el
index c5570331a6..e0bdb6d21f 100644
--- a/clj-lex.el
+++ b/clj-lex.el
@@ -91,9 +91,20 @@
(when (eq (char-after (point)) ?M)
(right-char))
- (clj-lex-token :number
- (buffer-substring-no-properties pos (point))
- pos)))
+ (let ((char (char-after (point))))
+ (if (and char (or (and (<= ?a char) (<= char ?z))
+ (and (<= ?A char) (<= char ?Z))
+ (and (member char '(?. ?* ?+ ?! ?- ?_ ?? ?$ ?& ?= ?<
?> ?/)))))
+ (progn
+ (right-char)
+ (clj-lex-token :lex-error
+ (buffer-substring-no-properties pos (point))
+ pos
+ 'error-type :invalid-number-format))
+
+ (clj-lex-token :number
+ (buffer-substring-no-properties pos (point))
+ pos)))))
(defun clj-lex-digit? (char)