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

Multi-line comments and indentation level #1350

Closed
aseemk opened this issue May 11, 2011 · 7 comments
Closed

Multi-line comments and indentation level #1350

aseemk opened this issue May 11, 2011 · 7 comments

Comments

@aseemk
Copy link
Contributor

aseemk commented May 11, 2011

Easier to show code than to try and describe the problem: ;)

https://gist.github.com/965677

It would be great if that first example worked, i.e. matching indentation level wasn't a requirement for multi-line comments. Makes e.g. commenting out chunks of code easier.

What do you think? Thanks in advance!

@gasi
Copy link

gasi commented May 11, 2011

+1

@michaelficarra
Copy link
Collaborator

See #934 for Jeremy's opinion on this.

@jashkenas
Copy link
Owner

It's not so much an opinion as an impossibility. Either we have to parse comments and pass them through to JS, or we lex them out ... Because block comments are currently passed through, they have to be syntactically valid, which means that they have to respect significant whitespace.

If you want to comment out a chunk of code, use regular (non-block) comments, and everything should be fine.

@aseemk
Copy link
Contributor Author

aseemk commented May 11, 2011

Understandable, and this explains to me why single-line comments are stripped out of Coffee (I always wondered about that, since the Coffee compiler's aim isn't to minify) -- I'm guessing that's simply to allow single-line comments to appear anywhere, without having to respect significant whitespace?

To clarify though, it's certainly theoretically possible to ignore expected whitespace when you encounter a multiline comment, no? I'm guessing it'd just take a lot of plumbing through the lexer?

@jashkenas
Copy link
Owner

Yes, you have that all right.

It's only theoretically possible to ignore whitespace when parsing a multiline comment -- if we entirely change our current strategy for parsing/passing-through comments, and remove them from the parsing equation.

Proposals have been made to lex them out of the token stream (as single-line comments currently are), and tag them on their nearest neighboring node, so that they don't have to encounter the parser at all. Then, in the AST side, they'd be moved to the nearest newline, or something -- it's complicated, and no one has taken a serious stab at making it work.

@aseemk
Copy link
Contributor Author

aseemk commented May 13, 2011

Thanks for explaining, Jeremy!

@GeoffreyBooth
Copy link
Collaborator

The first example,

for i in foo
    print 'hello'
###
hello?
###
    print 'world'

compiles now, as of #4572. Sorry it took awhile.

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

5 participants