-
Notifications
You must be signed in to change notification settings - Fork 429
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
[RFC] Be more lax with semicolons #1887
Conversation
Why isn’t this part of the grammar? |
^ Same question I like that it's a parser change but not a printer change for now. A bit safer. Edit:
Does that mean we might make accidental changes in the future that produce ambiguous grammar, since menhir doesn't know about these semicolon changes? |
Don't think it'll result in ambiguous grammar, since the semicolons get inserted at runtime. |
I'm also curious about the runtime impact (in the case when there are no syntax errors primarily). The benefit of this approach is that the grammar remains clean, and is much easier to understand. You can see from my previous approach to this problem how much uglier it made the grammar. The downside (not really) is that we cannot tell people that semicolons are optional. We are relaxed about semicolons as a developer time convenience in Still this approach is very helpful because it makes refmt much more usable and also makes autocompletion much more accurate in cases where you are editing text like this:
Because it is actually a valid parse, and so there's much less error recovery needed. |
The runtime impact should not be measurable (I didn't try so I might be wrong :D). Furthermore, there are some of low-hanging fruits that could improve performance more than this patch affects them. Once again, that doesn't mean these improvements would be perceptible (for compilation, the rest of the backend is still more expensive, so one can hope for a few percent improvements, for reformatting, the pretty-printer is significantly more expensive than the parser in my previous measurements). |
How will it look a function with multiple lines of side effects? |
let f = (x) => {
let x = foo
let y = bar;
x + y
} Or let f = (x) => {
foo;
bar;
baz
} Where |
@let-def looks nice more rust like, but how is this gonna behave with the formatter since it inserts ; even in the last line the expression to return |
Alright, I guess this is good to go? cc @jordwalke |
This patch allows to omit semi colons in front of other tokens (
let
,type
,module
, ...) when it is non-ambiguous.One can now write:
However, semicolons are still necessary in front of expressions (return position), as well as attributes and doc comments.