ruff/crates/ruff_python_parser/src
Dhruv Manilawala 33ac2867b7
Use non-parenthesized range for DebugText (#9953)
## Summary

This PR fixes the `DebugText` implementation to use the expression range
instead of the parenthesized range.

Taking the following code snippet as an example:
```python
x = 1
print(f"{  ( x  ) = }")
```

The output of running it would be:
```
  ( x  ) = 1
```

Notice that the whitespace between the parentheses and the expression is
preserved as is.

Currently, we don't preserve this information in the AST which defeats
the purpose of `DebugText` as the main purpose of the struct is to
preserve whitespaces _around_ the expression.

This is also problematic when generating the code from the AST node as
then the generator has no information about the parentheses the
whitespaces between them and the expression which would lead to the
removal of the parentheses in the generated code.

I noticed this while working on the f-string formatting where the debug
text would be used to preserve the text surrounding the expression in
the presence of debug expression. The parentheses were being dropped
then which made me realize that the problem is instead in the parser.

## Test Plan

1. Add a test case for the parser
2. Add a test case for the generator
2024-02-12 23:00:02 +05:30
..
lexer Use memchr for string lexing (#9888) 2024-02-08 17:23:06 +00:00
snapshots Use non-parenthesized range for DebugText (#9953) 2024-02-12 23:00:02 +05:30
context.rs Remove source path from parser errors (#9322) 2023-12-30 20:33:05 +00:00
function.rs Reduce size of Expr from 80 to 64 bytes (#9900) 2024-02-09 02:53:13 +00:00
invalid.rs Reduce Result<Tok, LexicalError> size by using Box<str> instead of String (#9885) 2024-02-08 20:36:22 +00:00
lexer.rs Reduce Result<Tok, LexicalError> size by using Box<str> instead of String (#9885) 2024-02-08 20:36:22 +00:00
lib.rs Remove unnecessary string cloning from the parser (#9884) 2024-02-09 16:03:27 -05:00
parser.rs Use non-parenthesized range for DebugText (#9953) 2024-02-12 23:00:02 +05:30
python.lalrpop Use non-parenthesized range for DebugText (#9953) 2024-02-12 23:00:02 +05:30
python.rs Use non-parenthesized range for DebugText (#9953) 2024-02-12 23:00:02 +05:30
soft_keywords.rs Reduce Result<Tok, LexicalError> size by using Box<str> instead of String (#9885) 2024-02-08 20:36:22 +00:00
string.rs Remove unnecessary string cloning from the parser (#9884) 2024-02-09 16:03:27 -05:00
token.rs Reduce Result<Tok, LexicalError> size by using Box<str> instead of String (#9885) 2024-02-08 20:36:22 +00:00
token_source.rs Remove type parameter from parse_* methods (#9466) 2024-01-11 19:41:19 +01:00
typing.rs Remove source path from parser errors (#9322) 2023-12-30 20:33:05 +00:00