Skip to content

Commit 3a34c92

Browse files
author
Yannick Scherer
committed
fix reading of symbols. (closes #25)
- fixes handling of "sym:sym". - fixes handling of "sym'sym".
1 parent b75a77e commit 3a34c92

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/rewrite_clj/parser/token.clj

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
[reader :as r]]))
55

66
(defn- read-to-boundary
7-
[reader]
8-
(r/read-until
9-
reader
10-
r/whitespace-or-boundary?))
7+
[reader & [allowed]]
8+
(let [allowed? (set allowed)]
9+
(r/read-until
10+
reader
11+
#(and (not (allowed? %))
12+
(r/whitespace-or-boundary? %)))))
1113

1214
(defn- read-to-char-boundary
1315
[reader]
@@ -18,15 +20,18 @@
1820
""))))
1921

2022
(defn- symbol-node
21-
"Symbols allow for trailing quotes that have to be handled
22-
explicitly."
23+
"Symbols allow for certain boundary characters that have
24+
to be handled explicitly."
2325
[reader value value-string]
24-
(if (= (r/peek reader) \')
25-
(let [s (str value-string (r/next reader))]
26-
(node/token-node
27-
(r/string->edn s)
28-
s))
29-
(node/token-node value value-string)))
26+
(let [suffix (read-to-boundary
27+
reader
28+
[\' \:])]
29+
(if (empty? suffix)
30+
(node/token-node value value-string)
31+
(let [s (str value-string suffix)]
32+
(node/token-node
33+
(r/string->edn s)
34+
s)))))
3035

3136
(defn parse-token
3237
"Parse a single token."

0 commit comments

Comments
 (0)