coffeescript
coffeescript copied to clipboard
Lexer: Provide more helpful error message for trailing colon
If you accidentally add a colon at the end of a line, like in Python, the CoffeeScript compiler (HEAD) produces rather unhelpful error messages. I ended up spending some time yesterday hunting down an extra colon in the middle of my source. ;-)
$ bin/coffee -sc
while 1:
1
Error: Parse error on line 2: Unexpected 'TERMINATOR'
$ bin/coffee -sc
for i in [1]:
1
Error: Parse error on line 1: Unexpected '{'
This is not really a bug, more like a nuisance -- just thought you might appreciate the report. Feel free to close it if there is nothing that can be done.
related: #1358
Notice that indentation isn't the issue here. Since
x:
func()
is a legitimate way of writing {x: func()}
,
while x:
func()
is erroneous only insofar as while {x: func()}
is (and indeed, that line gives you the same Unexpected 'TERMINATOR'
message).
Ideally, I'd want the compiler to say something like
Parse error on line 2: `while` requires a condition and an expression, but only a condition is given
This would indeed be really helpful. Coming from Python I had class:
somewhere in my code and had no idea that could be related to Unexpected 'TERMINATOR'
.
$ coffee -v
CoffeeScript version 1.9.2
$ coffee -e 'while 1:
> 1'
[stdin]:2:4: error: unexpected end of input
1
^
$ coffee -e 'for i in [1]:
> 1'
[stdin]:1:10: error: unexpected [
for i in [1]:
^
Seems like the latter case has been fixed, while the first case has changed but still isn’t good.