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

Comment syntax? #180

Closed
pmetzger opened this issue Apr 10, 2017 · 8 comments

Comments

@pmetzger
Copy link

commented Apr 10, 2017

I find myself wanting to comment my re2c grammar, but it isn't clear if there's any sort of text inside the re2c C comment block itself that won't be treated as though it is valid re2c code.

How can I do this cleanly? Is there some undocumented method?

@skvadrik

This comment has been minimized.

Copy link
Owner

commented Apr 10, 2017

Sure, both single-line comments // and multiliine comments /* ... */ should work.

@skvadrik

This comment has been minimized.

Copy link
Owner

commented Apr 10, 2017

Also, if you want to comment the whole /*!re2c ... */ block, the best way is just to put an extra space between /* and !re2c.

@pmetzger

This comment has been minimized.

Copy link
Author

commented Apr 10, 2017

You can't put a /* ... / inside a / ... */ comment unfortunately, they don't nest.
But you're saying I should be able to put a // anywhere inside the comment block anywhere and that will not be a problem?

@pmetzger

This comment has been minimized.

Copy link
Author

commented Apr 10, 2017

(And could that be documented?)

@skvadrik

This comment has been minimized.

Copy link
Owner

commented Apr 10, 2017

Well, inside of a re2c block you can have another multiline comment, but it will probably break your syntax highlighter. Single-line comments won't break syntax highlighter. Do you have an example of code that doesn't work?

As for documentation, I already added a reminder in #140.

@pmetzger

This comment has been minimized.

Copy link
Author

commented Apr 10, 2017

Is the reason a multi-line comment will work that re2c preprocesses the c-like comments in the first place? Because C itself does not allow nested comments.

@skvadrik

This comment has been minimized.

Copy link
Owner

commented Apr 10, 2017

Yes. re2c parses C/C++ code, finds multiline comments of the form /*!re2c ... */ (and a couple of variations) and parses the code inside of these comments.

This is the exact place in the re2c source code that handles nested multiline comments: https://github.com/skvadrik/re2c/blob/devel/re2c/src/ast/lex.re#L207, and this one handles single-line comments https://github.com/skvadrik/re2c/blob/devel/re2c/src/ast/lex.re#L204.

@pmetzger

This comment has been minimized.

Copy link
Author

commented Apr 10, 2017

Cool! Thank you so much!

@skvadrik skvadrik closed this Mar 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.