-
Notifications
You must be signed in to change notification settings - Fork 20
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
Define end-of-file trivia as part of the language definition #1020
Comments
I understand that the underlying rationale for not implicitly parsing the leading trivia in the runtime parser ("rolling back the hack") is to keep it explicit as part of the definition and so that's why I named this issue this way; feel free to rename it. |
Adding your comment from #1021 (comment)
I think the current leading_trivia = ZeroOrMore(Choice([
Trivia(Whitespace),
Trivia(EndOfLine),
Trivia(SingleLineComment),
Trivia(MultiLineComment),
Trivia(SingleLineNatSpecComment),
Trivia(MultiLineNatSpecComment)
])),
trailing_trivia = Optional(Sequence([
Optional(Trivia(Whitespace)),
Optional(Trivia(SingleLineComment)),
Trivia(EndOfLine)
])), Definitely not high-pri, but it is something we discussed in a few instances already, and it would be good to have a consensus written down here. |
I remember that we did discuss what to do with trailing trivia and that it's not so obvious, as for example
would mean that this conceptually would belong to the
}
token and this prompts the question of how to format it and adds inconsistency as our trailing trivia in general cannot span multiple lines.The way we have this setup is that the trailing trivia has to be a conceptually a subset of the leading trivia and thus the leading trivia is the trivia parser, which means if we want to accept all of the trivia items at EOF, then the leading trivia definition is correct for that use case and not a stretch, from what I understand (but, to be clear, we do have a "hack" of implicitly parsing the leading trivia rather than it having a dedicated definition in the definition.rs).
If we want to use the DSLv2's definition of (as added by this PR)
then for it to be correct, we'd have to change it to something like:
At which point we're de facto reintroducing end_of_file_trivia, now that I think about it. Given that it's different enough from the regular trailing trivia, should we just bite the bullet and be more explicit about it to not confuse the user and be clear about expectations?
Introducing a dedicated notion of end_of_file trivia would also mean we don't need to introduce this virtual
EndOfFile
trivia/token, which we all agreed at some point to not have magical/synthesized token in the definition that can't be directly parsed.@AntonyBlakey @OmarTawfik I don't think we did write down our different conclusions and rationale while we were discussing this on multiple occasions. If you're fine with it, I'd propose that we separate an issue/thread dedicated to it as I feel we had already too many items bundled in this issue and the decision is not clear-cut at this moment.
Originally posted by @Xanewok in #638 (comment)
The text was updated successfully, but these errors were encountered: