[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/parseclj 0afb8c5f09 123/185: Add `parseclj-lex-error-token
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/parseclj 0afb8c5f09 123/185: Add `parseclj-lex-error-token` helper |
Date: |
Tue, 28 Dec 2021 14:05:27 -0500 (EST) |
branch: elpa/parseclj
commit 0afb8c5f09922165e72b3ddc807e63057c246dea
Author: Daniel Barreto <daniel.barreto.n@gmail.com>
Commit: Daniel Barreto <daniel.barreto.n@gmail.com>
Add `parseclj-lex-error-token` helper
---
parseclj-lex.el | 25 +++++++++++++++++--------
test/parseclj-lex-test.el | 2 +-
2 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/parseclj-lex.el b/parseclj-lex.el
index ea8b65783c..11bb9663d5 100644
--- a/parseclj-lex.el
+++ b/parseclj-lex.el
@@ -57,6 +57,19 @@ 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."
+ (when (= pos (point))
+ (right-char))
+ (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 +206,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 +279,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 +331,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,7 +417,7 @@ 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)))))))
diff --git a/test/parseclj-lex-test.el b/test/parseclj-lex-test.el
index c1ebc09ce1..34813e3ac7 100644
--- a/test/parseclj-lex-test.el
+++ b/test/parseclj-lex-test.el
@@ -283,7 +283,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 987bd16a57 089/185: Position starts at 1, not at 0 (just like (point)), (continued)
- [nongnu] elpa/parseclj 987bd16a57 089/185: Position starts at 1, not at 0 (just like (point)), ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 313fc4e630 077/185: Rename to parseclj, ELPA Syncer, 2021/12/28
- [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 <=
- [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, 2021/12/28
- [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