Skip to content

Commit 05e9b83

Browse files
author
Yannick Scherer
committed
improve error reporting if forms are missing.
1 parent 3a34c92 commit 05e9b83

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

src/rewrite_clj/parser/core.clj

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@
4343
(reader/read-repeatedly reader)))
4444

4545
(defn- parse-printables
46-
[reader n & [ignore?]]
46+
[reader node-tag n & [ignore?]]
4747
(when ignore?
4848
(reader/ignore reader))
4949
(reader/read-n
5050
reader
51+
node-tag
5152
parse-next
5253
(complement node/printable-only?)
5354
n))
@@ -102,7 +103,7 @@
102103
(defmethod parse-next* :meta
103104
[reader]
104105
(reader/ignore reader)
105-
(node/meta-node (parse-printables reader 2)))
106+
(node/meta-node (parse-printables reader :meta 2)))
106107

107108
;; ### Reader Specialities
108109

@@ -114,35 +115,35 @@
114115
\{ (node/set-node (parse-delim reader \}))
115116
\( (node/fn-node (parse-delim reader \)))
116117
\" (parse-regex reader)
117-
\^ (node/raw-meta-node (parse-printables reader 2 true))
118-
\' (node/var-node (parse-printables reader 1 true))
119-
\= (node/eval-node (parse-printables reader 1 true))
120-
\_ (node/uneval-node (parse-printables reader 1 true))
121-
(node/reader-macro-node (parse-printables reader 2))))
118+
\^ (node/raw-meta-node (parse-printables reader :meta 2 true))
119+
\' (node/var-node (parse-printables reader :var 1 true))
120+
\= (node/eval-node (parse-printables reader :eval 1 true))
121+
\_ (node/uneval-node (parse-printables reader :uneval 1 true))
122+
(node/reader-macro-node (parse-printables reader :reader-macro 2))))
122123

123124
(defmethod parse-next* :deref
124125
[reader]
125-
(node/deref-node (parse-printables reader 1 true)))
126+
(node/deref-node (parse-printables reader :deref 1 true)))
126127

127128
;; ## Quotes
128129

129130
(defmethod parse-next* :quote
130131
[reader]
131-
(node/quote-node (parse-printables reader 1 true)))
132+
(node/quote-node (parse-printables reader :quote 1 true)))
132133

133134
(defmethod parse-next* :syntax-quote
134135
[reader]
135-
(node/syntax-quote-node (parse-printables reader 1 true)))
136+
(node/syntax-quote-node (parse-printables reader :syntax-quote 1 true)))
136137

137138
(defmethod parse-next* :unquote
138139
[reader]
139140
(reader/ignore reader)
140141
(let [c (reader/peek reader)]
141142
(if (= c \@)
142143
(node/unquote-splicing-node
143-
(parse-printables reader 1 true))
144+
(parse-printables reader :unquote 1 true))
144145
(node/unquote-node
145-
(parse-printables reader 1)))))
146+
(parse-printables reader :unquote 1)))))
146147

147148
;; ### Seqs
148149

src/rewrite_clj/reader.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
(defn read-n
131131
"Call the given function on the given reader until `n` values matching `p?` have been
132132
collected."
133-
[reader read-fn p? n]
133+
[reader node-tag read-fn p? n]
134134
{:pre [(pos? n)]}
135135
(loop [c 0
136136
vs []]
@@ -141,7 +141,8 @@
141141
(conj vs v))
142142
(throw-reader
143143
reader
144-
"expects %d value%s."
144+
"%s node expects %d value%s."
145+
node-tag
145146
n
146147
(if (= n 1) "" "s")))
147148
vs)))

test/rewrite_clj/parser_test.clj

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,13 @@
224224
"\"abc" #".*EOF.*"
225225
"#\"abc" #".*Unexpected EOF.*"
226226
"(def x 0]" #".*Unmatched delimiter.*"
227-
"#=" #".*expects 1 value.*"
228-
"#^" #".*expects 2 values.*"
229-
"^:private" #".*expects 2 values.*"
230-
"#^:private" #".*expects 2 values.*"
231-
"#macro" #".*expects 2 values.*")
227+
"#=" #".*:eval node expects 1 value.*"
228+
"#^" #".*:meta node expects 2 values.*"
229+
"^:private" #".*:meta node expects 2 values.*"
230+
"#^:private" #".*:meta node expects 2 values.*"
231+
"#_" #".*:uneval node expects 1 value.*"
232+
"#'" #".*:var node expects 1 value.*"
233+
"#macro" #".*:reader-macro node expects 2 values.*")
232234

233235
(fact "about parsing multiple forms"
234236
(let [s "1 2 3"

0 commit comments

Comments
 (0)