Skip to content

Commit

Permalink
Make list of symbol/keyword constituent characters a custom option
Browse files Browse the repository at this point in the history
  • Loading branch information
ikappaki committed Mar 26, 2022
1 parent f32c041 commit bd11cf4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
16 changes: 15 additions & 1 deletion parseclj-lex.el
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@

(require 'parseclj-alist)

(defcustom parseclj-lex-symbol-special-chars
'(?. ?* ?+ ?! ?- ?_ ?? ?$ ?% ?& ?= ?< ?> ?/ ?')
"The list of characters that can consitute a symbol or keyword's name.
Please note that Clojure might at runtime accept keywords with
more constituent characters than those found in the default value
of this variable (which is the officially supported list), but
the end result should be treated as undefined. This could be the
case for example when keywordized maps are created from external
sources without keyword validation. Change this value at your
own risk."
:type 'sexp
:group 'parseclj)

(defvar parseclj-lex--leaf-tokens '(:whitespace
:comment
:symbolic-value
Expand Down Expand Up @@ -303,7 +317,7 @@ alphabetic characters only. ALPHA-ONLY ensures this behavior."
(not (not (and char
(or (and (<= ?a char) (<= char ?z))
(and (<= ?A char) (<= char ?Z))
(and (not alpha-only) (member char '(?. ?* ?+ ?! ?- ?_ ?? ?$ ?% ?& ?= ?< ?> ?/ ?'))))))))
(and (not alpha-only) (member char parseclj-lex-symbol-special-chars)))))))

(defun parseclj-lex-symbol-rest-p (char)
"Return t if CHAR is a valid character in a symbol.
Expand Down
7 changes: 6 additions & 1 deletion test/parseclj-lex-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,12 @@
(should (equal (parseclj-lex-symbol-rest-p ?A) t))
(should (equal (parseclj-lex-symbol-rest-p ?.) t))
(should (equal (parseclj-lex-symbol-rest-p ?~) nil))
(should (equal (parseclj-lex-symbol-rest-p ? ) nil)))
(should (equal (parseclj-lex-symbol-rest-p ? ) nil))

(should (equal (parseclj-lex-symbol-rest-p ?|) nil))
(let ((parseclj-lex-symbol-special-chars (cons ?| parseclj-lex-symbol-special-chars)))
(should (equal (parseclj-lex-symbol-rest-p ?|) t)))
(should (equal (parseclj-lex-symbol-rest-p ?|) nil)))

(ert-deftest parseclj-lex-test-get-symbol-at-point ()
(with-temp-buffer
Expand Down

0 comments on commit bd11cf4

Please sign in to comment.