-
Notifications
You must be signed in to change notification settings - Fork 2k
Initial indent at start of a file #2981
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
Comments
seems like we should be avoiding that |
This is an awesome feature actually. Want to comment a gigantic file? Just type TAB /sarcasm |
I had a go at fixing it, but where @Nami-Doc pointed to is not the place to fix it, since leading indent is needed for interpolations (even though that seems like a hack as well). It should be fixed wherever CoffeeScript actually ignores the negatively indented code (and throw error), which is beyond my knowledge of the compiler. |
We can easily disable initial indent @jashkenas any reason we allow that? |
I think allowing initial indentation is quite handy in cases where you copy some code and want to, for example, paste it in coffeescript.org to see how it compiles. The copied code could have some level of indentation, but as long as that indentation is consistent, i don't see why the compiler should not allow it. What should not be allowed is having an initial indentation in the first line of code and then having some other line going below that level of indentation (i'd expect and "unexpected DEDENT" error or something like that). |
Ah, yeah, that's perfectly valid (saves so much time). We can keep track of "initial indent" in the lexer but we need to be sure we're not in an interpolation (we don't even flag the lexer yet), not in a string, not hacking with debts, etc.
I'd say in the grammar. We have :
So for
and Jison will give us these nodes :
Because Whereas if we have
Generating the correct AST :
|
CoffeeScriptRedux handles this in the preprocessor with the notion of "base" indentation. Since the parser can't handle an indentation stack, the preprocessor adds the indent/dedent markers appropriately. |
Would be easy if only we weren't creating new lexer instances, strange strings, newline suppression and some more. I tried to patch Lexer::lineToken to set |
So much statefulness! |
Also, considering the order : @identifierToken() or
@commentToken() or
@whitespaceToken() or
@lineToken() or we'd need to set |
I specially allowed
case for some weird reasons regarding string interpolation. If we're disallowing it, an easy way is to append an EOF to the token list and make Root require that. |
Edited my post with the relevant commit |
Checking for EOF seems to make the most sense to me (as grammars usually do). |
But would not give a really good error message |
It is not entirely clear ( unexpected negative indent ) but it also isn't useless. For some reason though, it breaks tabs in |
Is this is a language/compiler feature?
a ignored also ignored
compiles down to
Or an uncaught syntax error?
The text was updated successfully, but these errors were encountered: