-
Notifications
You must be signed in to change notification settings - Fork 428
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
Fix precedence issue with unary ops and labelled args #2201
Conversation
Awesome! Thanks for fixing. Any way we can avoid the parens around the number with unary minus since we know how to parse it correctly? |
The reason why this is getting so messy, is because unary parsing precedence is very tricky and has special behavior. You can see how it is designated as special in all the precedence rules. To lex a token, which is then parsed as an infix operator Diff 1642 which special cased |
When we see |
Would it be cleaner to bring back the special token for |
Indeed #1642 doesn't suffer from this bug. I'll refactor the PR to include that approach. |
After some more investigation, I think this is indeed a very hard problem. With the approach employed by #1642, these wouldn't parse: let x = (~a: int=- 1) => a;
let x: float=-.1; The reason being the type constraint. And making yet another special case in the lexer / parser to support this would IMO not justify the cost. |
What if remove all special logic in lexing/parsing and delay this "feature" to the error stage and recover there? |
@jordwalke My latest commit employs the suggestion given by @IwanKaramazow, delaying the parsing of labeled unary ops to the error recovery section. I feel like the code is much cleaner now as it removes the weird special tokens from the parser / lexer. I think this is ready for another round of review! |
If everyone agrees, I'll address this in a future PR to keep the change set here amenable for review. |
a5c1046
to
ead5789
Compare
Whatever works, you guys are the specialists! What I would say is that I hope nobody ever ever ever uses |
I'm glad you went with this general approach (thanks for the suggestion @IwanKaramazow). This helps avoid messing with the complicated precedence rules of shift/reduce and handles the squashing at an earlier stage. These earlier hacks to cover less important edge cases keep the overall grammar rules comprehensible. Similar to the approach with optional semicolons we could say that |
@jordwalke that's a good point, but if you think $ echo 'foo(~x=-.1);' | ./_build/install/default/bin/refmt
foo(~x=-. 1); |
fixes #2200