ruff/crates/ruff_python_formatter/src/other
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
..
alias.rs Avoid printing continuations within import identifiers (#7744) 2023-10-02 09:51:07 -04:00
arguments.rs Refactor with statement formatting to have explicit layouts (#10296) 2024-03-08 18:40:39 -05:00
bytes_literal.rs Simplify formatting of strings by using flags from the AST nodes (#10489) 2024-03-20 16:16:54 +00:00
commas.rs Replace LALRPOP parser with hand-written parser (#10036) 2024-04-18 17:57:39 +05:30
comprehension.rs Skip over parentheses when detecting in keyword (#8054) 2023-10-18 19:13:58 -04:00
decorator.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
elif_else_clause.rs Use the formatter prelude in more files (#6882) 2023-08-25 16:51:07 -04:00
except_handler_except_handler.rs Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
f_string.rs Simplify formatting of strings by using flags from the AST nodes (#10489) 2024-03-20 16:16:54 +00:00
f_string_element.rs Simplify formatting of strings by using flags from the AST nodes (#10489) 2024-03-20 16:16:54 +00:00
f_string_part.rs Split string formatting to individual nodes (#9058) 2023-12-14 12:55:10 -06:00
identifier.rs Range formatting: Fix invalid syntax after parenthesizing expression (#9751) 2024-02-02 17:56:25 +01:00
keyword.rs Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
match_case.rs Move {AnyNodeRef, AstNode} to ruff_python_ast crate root (#8030) 2023-10-18 00:01:18 +00:00
mod.rs Preview minimal f-string formatting (#9642) 2024-02-16 20:28:11 +05:30
parameter.rs Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
parameter_with_default.rs Formatter: Remove unnecessary group (#8455) 2023-11-03 04:14:29 +00:00
parameters.rs Fix trailing kwargs end of line comment after slash (#10297) 2024-03-08 14:45:26 +00:00
string_literal.rs Simplify formatting of strings by using flags from the AST nodes (#10489) 2024-03-20 16:16:54 +00:00
with_item.rs Formatter: Improve single-with item formatting for Python 3.8 or older (#10276) 2024-03-08 23:56:02 +00:00