[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/parseclj 46cfcd3120 129/185: Merge pull request #16 from l
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/parseclj 46cfcd3120 129/185: Merge pull request #16 from lambdaisland/parseclj-lex-error-token |
Date: |
Tue, 28 Dec 2021 14:05:28 -0500 (EST) |
branch: elpa/parseclj
commit 46cfcd312090537ea65c458b5373343f9054e1ed
Merge: 92396d11cf b26fadbc05
Author: Arne Brasseur <arne.brasseur@gmail.com>
Commit: GitHub <noreply@github.com>
Merge pull request #16 from lambdaisland/parseclj-lex-error-token
Return `:lex-error` token when there's invalid input in `parseclj-lex-next`
---
parseclj-lex.el | 27 ++++++++++++++++++---------
test/parseclj-lex-test.el | 9 +++++++--
2 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/parseclj-lex.el b/parseclj-lex.el
index ea8b65783c..f23580d5dd 100644
--- a/parseclj-lex.el
+++ b/parseclj-lex.el
@@ -57,6 +57,17 @@ Tokens at a mimimum have these attributes
Other ATTRIBUTES can be given as a flat list of key-value pairs."
(apply 'a-list :token-type type :form form :pos pos attributes))
+(defun parseclj-lex-error-token (pos &optional error-type)
+ "Create a lexer error token starting at POS.
+ERROR-TYPE is an optional keyword to attach to the created token,
+as the means for providing more information on the error."
+ (apply #'parseclj-lex-token
+ :lex-error
+ (buffer-substring-no-properties pos (point))
+ pos
+ (when error-type
+ (list :error-type error-type))))
+
(defun parseclj-lex-token-p (token)
"Is the given TOKEN a parseclj-lex TOKEN.
@@ -193,11 +204,7 @@ A token is an association list with :token-type as its
first key."
(and (member char '(?. ?* ?+ ?! ?- ?_ ?? ?$ ?& ?= ?<
?> ?/)))))
(progn
(right-char)
- (parseclj-lex-token :lex-error
- (buffer-substring-no-properties pos (point))
- pos
- :error-type :invalid-number-format))
-
+ (parseclj-lex-error-token pos :invalid-number-format))
(parseclj-lex-token :number
(buffer-substring-no-properties pos (point))
pos)))))
@@ -270,7 +277,7 @@ token is returned."
(progn
(right-char)
(parseclj-lex-token :string (buffer-substring-no-properties pos
(point)) pos))
- (parseclj-lex-token :lex-error (buffer-substring-no-properties pos
(point)) pos))))
+ (parseclj-lex-error-token pos :invalid-string))))
(defun parseclj-lex-lookahead (n)
"Return a lookahead string of N characters after point."
@@ -322,7 +329,7 @@ See `parseclj-lex-symbol', `parseclj-lex-symbol-start-p'."
(if (equal (char-after (point)) ?:) ;; three colons in a row => lex-error
(progn
(right-char)
- (parseclj-lex-token :lex-error (buffer-substring-no-properties pos
(point)) pos :error-type :invalid-keyword))
+ (parseclj-lex-error-token pos :invalid-keyword))
(progn
(while (or (parseclj-lex-symbol-rest-p (char-after (point)))
(equal (char-after (point)) ?#))
@@ -408,10 +415,12 @@ See `parseclj-lex-token'."
(while (not (or (parseclj-lex-at-whitespace-p)
(parseclj-lex-at-eof-p)))
(right-char))
- (parseclj-lex-token :lex-error (buffer-substring-no-properties pos
(point)) pos :error-type :invalid-hashtag-dispatcher)))))
+ (parseclj-lex-error-token pos :invalid-hashtag-dispatcher)))))
(t
- (concat ":(" (char-to-string char)))))))
+ (progn
+ (right-char)
+ (parseclj-lex-error-token pos)))))))
(provide 'parseclj-lex)
diff --git a/test/parseclj-lex-test.el b/test/parseclj-lex-test.el
index c1ebc09ce1..1918863abb 100644
--- a/test/parseclj-lex-test.el
+++ b/test/parseclj-lex-test.el
@@ -203,7 +203,12 @@
(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 "~")
+ (goto-char 1)
+ (should (equal (parseclj-lex-next) (parseclj-lex-token :lex-error "~"
1)))))
(ert-deftest parseclj-lex-test-at-number-p ()
(dolist (str '("123" ".9" "+1" "0" "-456"))
@@ -283,7 +288,7 @@
(with-temp-buffer
(insert "\"abc")
(goto-char 1)
- (should (equal (parseclj-lex-string) (parseclj-lex-token :lex-error
"\"abc" 1))))
+ (should (equal (parseclj-lex-string) (parseclj-lex-token :lex-error
"\"abc" 1 :error-type :invalid-string))))
(with-temp-buffer
(insert "\"abc\\\"\"")"abc\""
- [nongnu] elpa/parseclj 7f8bcd405e 095/185: Make checkdoc happy with parseclj.el, (continued)
- [nongnu] elpa/parseclj 7f8bcd405e 095/185: Make checkdoc happy with parseclj.el, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 0f16fcf2fa 084/185: Implement parsing with lexical preservation (keep whitespace, comments), ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj ca854455f6 099/185: Add missing requirement to `parseedn`, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj adbc0cabf5 100/185: Move `parseclj--{leaf, closing}-tokens` to `parseclj-lex` module, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 7794d9ee59 101/185: Add docstrings for `parseclj-lex` module, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 296a093132 102/185: Remove `parseclj-unparse`, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj d6525d30c6 111/185: Merge pull request #10 from lambdaisland/fix-ast-reduce-tag, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 0ef32ad912 120/185: Add support for having single quotes in symbols/keywords, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 0afb8c5f09 123/185: Add `parseclj-lex-error-token` helper, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj b2588ce0fb 126/185: Use EVM to setup Travis CI, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 46cfcd3120 129/185: Merge pull request #16 from lambdaisland/parseclj-lex-error-token,
ELPA Syncer <=
- [nongnu] elpa/parseclj 61577603f2 136/185: Update README.md with installation and usage information, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj a82f229014 139/185: Ignore *.elc files, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 7fba1624e0 142/185: Update DESIGN.md to name difference between parseclj and parseedn, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 3693dd148f 145/185: Fix Cask file, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj af6102c4a8 146/185: Minor fix to README file, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 91c2ad82af 147/185: Add enough feature to be able to parse clojure.core, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj b40670a561 149/185: Add namespaced maps, fix backquote implementation, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj ff0443c27c 151/185: Add :read-one option, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 40e36c41eb 006/185: alist-get was only introduced in 25.1? :sadpanda:, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 6f36bbf6b4 009/185: Try to set up a build matrix, ELPA Syncer, 2021/12/28