ruff/crates/ruff_python_parser
Dhruv Manilawala 5b81b8368d
Make associativity a property of operator precedence (#11065)
## Summary

This PR does a few things but the main change is that is makes
associativity a property of operator precedence.

1. Rename `Precedence` -> `OperatorPrecedence`
2. Rename `parse_expression_with_precedence` ->
`parse_binary_expression_or_higher`
3. Move `current_binding_power` to `OperatorPrecedence::try_from_tokens`
[^1]
4. Add a `OperatorPrecedence::is_right_associative` method
5. Move from `increment_precedence` to using `<=` / `<` to check if the
parsing loop needs to stop [^2]

[^1]: Another alternative would be to have two separate methods to avoid
lookahead as it's required only for once case (`not in`). So,
`try_from_current_token(current).or_else(|| try_from_next_token(current,
peek))`
[^2]: This will allow us to easily make the refactors mentioned in
#10752

## Test Plan

Make sure the precedence parsing algorithm is still correct by running
the test suite, fuzz testing it and running it against a dozen or so
open-source repositories.
2024-04-23 04:28:46 +00:00
..
resources Add ExpressionContext for expression parsing (#11055) 2024-04-23 04:19:05 +00:00
src Make associativity a property of operator precedence (#11065) 2024-04-23 04:28:46 +00:00
tests Add ExpressionContext for expression parsing (#11055) 2024-04-23 04:19:05 +00:00
Cargo.toml Add ExpressionContext for expression parsing (#11055) 2024-04-23 04:19:05 +00:00
CONTRIBUTING.md Replace LALRPOP parser with hand-written parser (#10036) 2024-04-18 17:57:39 +05:30