ruff
5b81b836 - Make associativity a property of operator precedence (#11065)

Comment changes are shownComment changes are hidden
Commit
1 year ago
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.
Author
Parents
  • crates/ruff_python_parser/src/parser
    • File
      expression.rs
    • File
      statement.rs