ruff/crates/ruff_python_parser/src
Dhruv Manilawala 47c9ed07f2
Consider 2-character EOL before line continuation (#12035)
## Summary

This PR fixes a bug introduced in
https://github.com/astral-sh/ruff/pull/12008 which didn't consider the
two character newline after the line continuation character.

For example, consider the following code highlighted with whitespaces:
```py
call(foo # comment \\r\n
\r\n
def bar():\r\n
....pass\r\n
```
The lexer is at `def` when it's running the re-lexing logic and trying
to move back to a newline character. It encounters `\n` and it's being
escaped (incorrect) but `\r` is being escaped, so it moves the lexer to
`\n` character. This creates an overlap in token ranges which causes the
panic.

```
Name 0..4
Lpar 4..5
Name 5..8
Comment 9..20
NonLogicalNewline 20..22 <-- overlap between
Newline 21..22           <-- these two tokens
NonLogicalNewline 22..23
Def 23..26
...
```

fixes: #12028 

## Test Plan

Add a test case with line continuation and windows style newline
character.
2024-06-26 14:00:48 +05:30
..
lexer Maintain synchronicity between the lexer and the parser (#11457) 2024-06-03 18:23:50 +05:30
parser Add syntax error for empty type parameter list (#12030) 2024-06-26 08:10:35 +05:30
snapshots Lexer should consider BOM for the start offset (#11732) 2024-06-04 08:45:46 +00:00
error.rs Add syntax error for empty type parameter list (#12030) 2024-06-26 08:10:35 +05:30
lexer.rs Consider 2-character EOL before line continuation (#12035) 2024-06-26 14:00:48 +05:30
lib.rs Move token and error structs into related modules (#11957) 2024-06-21 10:07:19 +00:00
string.rs Move token and error structs into related modules (#11957) 2024-06-21 10:07:19 +00:00
token.rs Manual impl of Debug on Token (#11958) 2024-06-22 04:18:24 +00:00
token_set.rs Replace LALRPOP parser with hand-written parser (#10036) 2024-04-18 17:57:39 +05:30
token_source.rs Move token and error structs into related modules (#11957) 2024-06-21 10:07:19 +00:00
typing.rs Update type annotation parsing API to return Parsed (#11739) 2024-06-05 12:59:43 +05:30