Skip to content

Commit

Permalink
drop support for multiple / in keywords and symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
carocad committed Nov 3, 2020
1 parent 57135df commit 718de49
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
12 changes: 6 additions & 6 deletions src/Clojure.g4
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,14 @@ OCTAL_CHAR: ESCAPE 'o' ([0-7] | ([0-7] [0-7]) | ([0-3] [0-7] [0-7]));

fragment ESCAPE: '\\';

// Parcera currently (01.11.20) doesnt support multiple / inside
// keywords nor symbols as documented in https://clojure.org/reference/reader#_symbols
// See https://github.com/carocad/parcera/pull/94 for a more indept discussion.

// ::/ is NOT a valid macro keyword, unlike :/
// multiple / are allowed for backward compatibility
MACRO_KEYWORD: '::' (SIMPLE_KEYWORD '/'+)* SIMPLE_KEYWORD;
MACRO_KEYWORD: '::' (SIMPLE_KEYWORD '/')? SIMPLE_KEYWORD;

// multiple / are allowed for backward compatibility
KEYWORD: ':' (SIMPLE_KEYWORD '/'+)* (SIMPLE_KEYWORD | '/');
KEYWORD: ':' (SIMPLE_KEYWORD '/')? (SIMPLE_KEYWORD | '/');

fragment SIMPLE_KEYWORD: // a single character like + -
KEYWORD_HEAD
Expand All @@ -210,8 +211,7 @@ fragment KEYWORD_BODY: KEYWORD_HEAD | ':';

fragment KEYWORD_HEAD: ALLOWED_NAME_CHARACTER | DIGIT | [#'] | SIGN;
// multiple / are allowed for backward compatibility
SYMBOL: (SIMPLE_SYMBOL '/'+)* (SIMPLE_SYMBOL | '/');
SYMBOL: (SIMPLE_SYMBOL '/')? (SIMPLE_SYMBOL | '/');
fragment SIMPLE_SYMBOL: // a single character like + - / etc
(ALLOWED_NAME_CHARACTER | SIGN)
Expand Down
30 changes: 18 additions & 12 deletions test/parcera/test_cases.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,14 @@
(is (parcera/failure? (parcera/ast input))))
(let [input "A/A:0"]
(is (= (parcera/ast input) [:code [:symbol input]])))
(let [input "hello//a/"]
(is (parcera/failure? (parcera/ast input))))
(let [input "hello///"]
(valid? input)
(roundtrip input)))
;; todo: the followings are NOT valid literal symbols but they are
;; "supported" by the current LispReader implementation
;; hopefully in the future it won't; see CLJ-1530
#_(let [input "hello//a/"]
(is (parcera/failure? (parcera/ast input))))
#_(let [input "hello///"]
(valid? input)
(roundtrip input)))


(deftest tag-literals
Expand Down Expand Up @@ -241,17 +244,20 @@
(let [input ":#hello"]
(valid? input)
(roundtrip input))
;; this is NOT a valid literal keyword but it is "supported" by the current
;; reader
;; todo: the followings are NOT valid literal keyword but they are
;; "supported" by the current LispReader implementation
;; hopefully in the future it won't; see CLJ-1530
(let [inputs [":http://www.department0.university0.edu/GraduateCourse52"
"::platform/http://www.department0.university0.edu/GraduateCourse52"
":hello/world/foo"
":hello/world/f:oo"
"::platform/foo/bar"]]
(doseq [input inputs]
(valid? input)
(roundtrip input)))
(let [inputs [":hello/world/" "::hello/world/" ":7/"]]
"::platform/foo/bar"
#_(doseq [input inputs]
(valid? input)
(roundtrip input))
":hello/world/"
"::hello/world/"
":7/"]]
(doseq [input inputs]
(is (parcera/failure? (parcera/ast input))))))

Expand Down

0 comments on commit 718de49

Please sign in to comment.