ruff/crates/ruff_python_parser/src
Brent Westbrook 78806361fd
Start detecting version-related syntax errors in the parser (#16090)
## Summary

This PR builds on the changes in #16220 to pass a target Python version
to the parser. It also adds the `Parser::unsupported_syntax_errors` field, which
collects version-related syntax errors while parsing. These syntax
errors are then turned into `Message`s in ruff (in preview mode).

This PR only detects one syntax error (`match` statement before Python
3.10), but it has been pretty quick to extend to several other simple
errors (see #16308 for example).

## Test Plan

The current tests are CLI tests in the linter crate, but these could be
supplemented with inline parser tests after #16357.

I also tested the display of these syntax errors in VS Code:


![image](https://github.com/user-attachments/assets/062b4441-740e-46c3-887c-a954049ef26e)

![image](https://github.com/user-attachments/assets/101f55b8-146c-4d59-b6b0-922f19bcd0fa)

---------

Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
2025-02-25 23:03:48 -05:00
..
lexer Mention that Cursor is based on rustc's implementation. (#12109) 2024-06-30 16:53:25 +01:00
parser Start detecting version-related syntax errors in the parser (#16090) 2025-02-25 23:03:48 -05:00
snapshots Update insta snapshots (#14366) 2024-11-15 19:31:15 +01:00
error.rs Start detecting version-related syntax errors in the parser (#16090) 2025-02-25 23:03:48 -05:00
lexer.rs Parse triple quoted string annotations as if parenthesized (#15387) 2025-01-16 11:38:15 +05:30
lib.rs Start detecting version-related syntax errors in the parser (#16090) 2025-02-25 23:03:48 -05:00
string.rs Upgrade to Rust 1.81 (#13265) 2024-09-06 15:09:09 +02:00
token.rs [pylint] Do not offer fix for raw strings (PLE251) (#16132) 2025-02-13 08:36:11 +00:00
token_set.rs Replace LALRPOP parser with hand-written parser (#10036) 2024-04-18 17:57:39 +05:30
token_source.rs Use TokenSource to find new location for re-lexing (#12060) 2024-06-27 17:12:39 +05:30
typing.rs Rename ExprStringLiteral::as_unconcatenated_string() to ExprStringLiteral::as_single_part_string() (#16253) 2025-02-19 16:06:57 +00:00