@@ -35,13 +35,16 @@ exports.pare = (code, filename) ->
3535
3636 shorten res
3737
38+ prefixError = (state ) ->
39+ " #{ state .path or " FILE" } (#{ state .y } :#{ state .x } )"
40+
3841# eof
3942
4043_escape_eof = (xs , buffer , state , code ) ->
41- throw new Error " EOF in escape state"
44+ throw new Error " #{ prefixError (state) } EOF in escape state"
4245
4346_string_eof = (xs , buffer , state , code ) ->
44- throw new Error " EOF in string state"
47+ throw new Error " #{ prefixError (state) } EOF in string state"
4548
4649_space_eof = (xs , buffer , state , code ) ->
4750 xs
@@ -59,7 +62,7 @@ _indent_eof = (xs, buffer, state, code) ->
5962# escape
6063
6164_escape_newline = (xs , buffer , state , code ) ->
62- throw new Error ' newline while escape'
65+ throw new Error " #{ prefixError (state) } newline while escape"
6366
6467_escape_n = (xs , buffer , state , code ) ->
6568 state .x += 1
@@ -87,7 +90,7 @@ _string_backslash = (xs, buffer, state, code) ->
8790 [xs, buffer, state, code[1 .. ]]
8891
8992_string_newline = (xs , buffer , state , code ) ->
90- throw new Error ' newline in a string'
93+ throw new Error " #{ prefixError (state) } newline in a string"
9194
9295_string_quote = (xs , buffer , state , code ) ->
9396 state .name = ' token'
@@ -126,7 +129,7 @@ _space_close = (xs, buffer, state, code) ->
126129 state .nest -= 1
127130 state .level -= 1
128131 if state .nest < 0
129- throw new Error ' close at space'
132+ throw new Error " #{ prefixError (state) } close at space"
130133 state .x += 1
131134 [xs, buffer, state, code[1 .. ]]
132135
@@ -173,7 +176,7 @@ _token_newline = (xs, buffer, state, code) ->
173176 [xs, buffer, state, code[1 .. ]]
174177
175178_token_open = (xs , buffer , state , code ) ->
176- throw new Error ' open parenthesis in token'
179+ throw new Error " #{ prefixError (state) } open parenthesis in token"
177180
178181_token_close = (xs , buffer , state , code ) ->
179182 state .name = ' space'
@@ -207,12 +210,12 @@ _indent_newilne = (xs, buffer, state, code) ->
207210 [xs, buffer, state, code[1 .. ]]
208211
209212_indent_close = (xs , buffer , state , code ) ->
210- throw new Error ' close parenthesis at indent'
213+ throw new Error " #{ prefixError (state) } close parenthesis at indent"
211214
212215_indent_else = (xs , buffer , state , code ) ->
213216 state .name = ' space'
214217 if (state .indented % 2 ) is 1
215- throw new Error ' odd indentation'
218+ throw new Error " #{ prefixError (state) } odd indentation"
216219 indented = state .indented / 2
217220 diff = indented - state .indent
218221
@@ -238,22 +241,22 @@ parse = (xs, buffer, state, code) ->
238241 when ' escape'
239242 if eof then _escape_eof args...
240243 else switch char
241- when ' \r ' , ' \n ' then _escape_newline args...
244+ when ' \r ' , ' \n ' then _escape_newline args...
242245 when ' n' then _escape_n args...
243246 when ' t' then _escape_t args...
244247 else _escape_else args...
245248 when ' string'
246249 if eof then _string_eof args...
247250 else switch char
248251 when ' \\ ' then _string_backslash args...
249- when ' \r ' , ' \n ' then _string_newline args...
252+ when ' \r ' , ' \n ' then _string_newline args...
250253 when ' "' then _string_quote args...
251254 else _string_else args...
252255 when ' space'
253256 if eof then _space_eof args...
254257 else switch char
255258 when ' ' then _space_space args...
256- when ' \r ' , ' \n ' then _space_newline args...
259+ when ' \r ' , ' \n ' then _space_newline args...
257260 when ' (' then _space_open args...
258261 when ' )' then _space_close args...
259262 when ' "' then _space_quote args...
@@ -262,7 +265,7 @@ parse = (xs, buffer, state, code) ->
262265 if eof then _token_eof args...
263266 else switch char
264267 when ' ' then _token_space args...
265- when ' \r ' , ' \n ' then _token_newline args...
268+ when ' \r ' , ' \n ' then _token_newline args...
266269 when ' (' then _token_open args...
267270 when ' )' then _token_close args...
268271 when ' "' then _token_quote args...
@@ -271,6 +274,6 @@ parse = (xs, buffer, state, code) ->
271274 if eof then _indent_eof args...
272275 else switch char
273276 when ' ' then _indent_space args...
274- when ' \r ' , ' \n ' then _indent_newilne args...
277+ when ' \r ' , ' \n ' then _indent_newilne args...
275278 when ' )' then _indent_close args...
276279 else _indent_else args...
0 commit comments