ruff/crates/ruff_python_formatter/src
Dhruv Manilawala 13ffb5bc19
Replace LALRPOP parser with hand-written parser (#10036)
(Supersedes #9152, authored by @LaBatata101)

## Summary

This PR replaces the current parser generated from LALRPOP to a
hand-written recursive descent parser.

It also updates the grammar for [PEP
646](https://peps.python.org/pep-0646/) so that the parser outputs the
correct AST. For example, in `data[*x]`, the index expression is now a
tuple with a single starred expression instead of just a starred
expression.

Beyond the performance improvements, the parser is also error resilient
and can provide better error messages. The behavior as seen by any
downstream tools isn't changed. That is, the linter and formatter can
still assume that the parser will _stop_ at the first syntax error. This
will be updated in the following months.

For more details about the change here, refer to the PR corresponding to
the individual commits and the release blog post.

## Test Plan

Write _lots_ and _lots_ of tests for both valid and invalid syntax and
verify the output.

## Acknowledgements

- @MichaReiser for reviewing 100+ parser PRs and continuously providing
guidance throughout the project
- @LaBatata101 for initiating the transition to a hand-written parser in
#9152
- @addisoncrump for implementing the fuzzer which helped
[catch](https://github.com/astral-sh/ruff/pull/10903)
[a](https://github.com/astral-sh/ruff/pull/10910)
[lot](https://github.com/astral-sh/ruff/pull/10966)
[of](https://github.com/astral-sh/ruff/pull/10896)
[bugs](https://github.com/astral-sh/ruff/pull/10877)

---------

Co-authored-by: Victor Hugo Gomes <labatata101@linuxmail.org>
Co-authored-by: Micha Reiser <micha@reiser.io>
2024-04-18 17:57:39 +05:30
..
comments Replace LALRPOP parser with hand-written parser (#10036) 2024-04-18 17:57:39 +05:30
expression Replace LALRPOP parser with hand-written parser (#10036) 2024-04-18 17:57:39 +05:30
module Replace LALRPOP parser with hand-written parser (#10036) 2024-04-18 17:57:39 +05:30
other Replace LALRPOP parser with hand-written parser (#10036) 2024-04-18 17:57:39 +05:30
pattern Update Rust to v1.77 (#10510) 2024-03-21 12:10:33 -04:00
snapshots Remove exception-handler lexing from unused-bound-exception fix (#5851) 2023-07-18 18:27:46 +00:00
statement Formatter: Improve single-with item formatting for Python 3.8 or older (#10276) 2024-03-08 23:56:02 +00:00
string Simplify formatting of strings by using flags from the AST nodes (#10489) 2024-03-20 16:16:54 +00:00
type_param Don't move type param opening parenthesis comment (#8163) 2023-10-24 12:02:27 +00:00
builders.rs Refactor with statement formatting to have explicit layouts (#10296) 2024-03-08 18:40:39 -05:00
cli.rs Remove type parameter from parse_* methods (#9466) 2024-01-11 19:41:19 +01:00
context.rs chore: remove repetitive words (#10502) 2024-03-21 03:57:16 +00:00
generated.rs Remove Expr postfix from ExprNamed, ExprIf, and ExprGenerator (#10229) 2024-03-04 12:55:01 +01:00
lib.rs Replace LALRPOP parser with hand-written parser (#10036) 2024-04-18 17:57:39 +05:30
main.rs Formatter and parser refactoring (#7569) 2023-09-26 15:29:43 +02:00
options.rs Preview minimal f-string formatting (#9642) 2024-02-16 20:28:11 +05:30
prelude.rs Accept any Into<AnyNodeRef> as Comments arguments (#5205) 2023-06-20 16:49:21 +00:00
preview.rs Formatter: Improve single-with item formatting for Python 3.8 or older (#10276) 2024-03-08 23:56:02 +00:00
range.rs Replace LALRPOP parser with hand-written parser (#10036) 2024-04-18 17:57:39 +05:30
shared_traits.rs ruff_python_formatter: copy and inline shared traits (#8656) 2023-11-13 12:16:04 -05:00
verbatim.rs Preview minimal f-string formatting (#9642) 2024-02-16 20:28:11 +05:30