Comments ending in a colon lead to error #18

Closed
aseemk opened this Issue May 11, 2011 · 5 comments

Comments

Projects
None yet
2 participants

aseemk commented May 11, 2011

https://gist.github.com/966242

Trailing colons in comments should be ignored. =)

aseemk commented May 11, 2011

The funny thing was that this error took me a long time to realize! The error message is completely misleading: Unexpected 'INDENT'.

Owner

sstephenson commented May 24, 2011

Eco doesn't really know anything about comments... it just passes them off to CoffeeScript.

We can detect comment tags by modifying the scanner to explicitly look for /^\s*#/ in the tag content. Would you like to take a shot at patching this?

aseemk commented May 24, 2011

Ah, perhaps looking at it from a different perspective will help:

Yes, Eco doesn't know about CoffeeScript syntax, e.g. comments. But CoffeeScript doesn't know about colons -- that's purely an Eco addition.

To my understanding, Eco's colon is a way of signaling "begin an indentation block" for e.g. if, for, while, etc. The problem here is, Eco does this with colons indiscriminately, even when the colon is at the end of a comment.

So should the solution be for Eco to manually detect comments? Or should it be to detect colons only when the statement is an if, for, etc.?

Owner

sstephenson commented May 24, 2011

Yes, that's certainly one way to look at it, but it doesn't reflect how Eco is designed. Eco does not parse CoffeeScript. It does know how to automatically dedent on the few keywords that require it (like else), but otherwise it's a simple set of preprocessing rules for compiling down to CoffeeScript source.

Scanning for # at the beginning of a tag will be far simpler to implement than parsing the source and checking for every possible keyword that can be followed by a newline + indent.

aseemk commented Jul 14, 2011

Whoa, I never got notified that you fixed this, so even though this is overdue, thanks for fixing! /cc @gasi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment