-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix curly brace escape handling in f-strings #7331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
0cc8221
Add support for the new f-string tokens per PEP 701
dhruvmanila 12a7c3a
Emit empty `FStringMiddle` token for special case
dhruvmanila 72f9a21
Update comment from code review
dhruvmanila 0159ae0
Avoid tracking parentheses nesting multiple times
dhruvmanila 63f43dc
Add test for empty `FStringMiddle` tok in lambda expr
dhruvmanila bfa0296
Code review changes
dhruvmanila 5db6b20
Emit empty token only in format spec, handle SingleRBrace error
dhruvmanila be4a3eb
Fix incorrect position to start the f-string token
dhruvmanila adb7a05
Update snapshots
dhruvmanila 22cfd95
Pass in the source code to the parser
dhruvmanila 408c58f
Add support for parsing f-strings as per PEP 701
dhruvmanila b70048a
Skip the empty `FStringMiddle` token emitted by lexer
dhruvmanila e8dade0
Remove unused error type, fix test case
dhruvmanila ab09524
Add some more f-string test cases
dhruvmanila cdc7b45
Code review changes
dhruvmanila 19653a3
Pass arguments in the correct order
dhruvmanila 9d8012d
Use narrow types for string parsing patterns
dhruvmanila 18188d0
Remove single string literal pattern
dhruvmanila 47c3215
Fix typo (`@L` -> `@R`)
dhruvmanila 06ba358
Disallow non-parenthesized lambda expr in f-string
dhruvmanila 44f3155
Fix curly brace escape handling for f-strings
dhruvmanila a8e4218
Merge branch 'dhruv/pep-701' into dhruv/fstring-parser-4
dhruvmanila File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
..._python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_escape_braces.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| --- | ||
| source: crates/ruff_python_parser/src/lexer.rs | ||
| expression: lex_source(source) | ||
| --- | ||
| [ | ||
| ( | ||
| FStringStart, | ||
| 0..2, | ||
| ), | ||
| ( | ||
| FStringMiddle { | ||
| value: "\\", | ||
| is_raw: false, | ||
| }, | ||
| 2..3, | ||
| ), | ||
| ( | ||
| Lbrace, | ||
| 3..4, | ||
| ), | ||
| ( | ||
| Name { | ||
| name: "foo", | ||
| }, | ||
| 4..7, | ||
| ), | ||
| ( | ||
| Rbrace, | ||
| 7..8, | ||
| ), | ||
| ( | ||
| FStringEnd, | ||
| 8..9, | ||
| ), | ||
| ( | ||
| FStringStart, | ||
| 10..12, | ||
| ), | ||
| ( | ||
| FStringMiddle { | ||
| value: "\\\\", | ||
| is_raw: false, | ||
| }, | ||
| 12..14, | ||
| ), | ||
| ( | ||
| Lbrace, | ||
| 14..15, | ||
| ), | ||
| ( | ||
| Name { | ||
| name: "foo", | ||
| }, | ||
| 15..18, | ||
| ), | ||
| ( | ||
| Rbrace, | ||
| 18..19, | ||
| ), | ||
| ( | ||
| FStringEnd, | ||
| 19..20, | ||
| ), | ||
| ( | ||
| FStringStart, | ||
| 21..23, | ||
| ), | ||
| ( | ||
| FStringMiddle { | ||
| value: "\\{foo}", | ||
| is_raw: false, | ||
| }, | ||
| 23..31, | ||
| ), | ||
| ( | ||
| FStringEnd, | ||
| 31..32, | ||
| ), | ||
| ( | ||
| FStringStart, | ||
| 33..35, | ||
| ), | ||
| ( | ||
| FStringMiddle { | ||
| value: "\\\\{foo}", | ||
| is_raw: false, | ||
| }, | ||
| 35..44, | ||
| ), | ||
| ( | ||
| FStringEnd, | ||
| 44..45, | ||
| ), | ||
| ( | ||
| Newline, | ||
| 45..45, | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.