Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lexer: Provide more helpful error message for trailing colon #1828

Open
joliss opened this issue Nov 5, 2011 · 4 comments
Open

Lexer: Provide more helpful error message for trailing colon #1828

joliss opened this issue Nov 5, 2011 · 4 comments

Comments

@joliss
Copy link
Contributor

joliss commented Nov 5, 2011

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.

@michaelficarra
Copy link
Collaborator

related: #1358

@TrevorBurnham
Copy link
Collaborator

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

@niklasf
Copy link

niklasf commented Oct 29, 2012

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'.

@lydell
Copy link
Collaborator

lydell commented May 1, 2015

$ 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.

@GeoffreyBooth GeoffreyBooth changed the title Provide more helpful error message for trailing colon Lexer: Provide more helpful error message for trailing colon May 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants