MCPcopy Create free account
hub / github.com/astral-sh/ruff / create_error

Method create_error

crates/ruff_python_parser/src/parser/mod.rs:1499–1594  ·  view source on GitHub ↗
(self, p: &Parser)

Source from the content-addressed store, hash-verified

1497 }
1498
1499 fn create_error(self, p: &Parser) -> ParseErrorType {
1500 match self {
1501 RecoveryContextKind::ModuleStatements | RecoveryContextKind::BlockStatements => {
1502 if p.at(TokenKind::Indent) {
1503 ParseErrorType::UnexpectedIndentation
1504 } else {
1505 ParseErrorType::OtherError("Expected a statement".to_string())
1506 }
1507 }
1508 RecoveryContextKind::Elif => ParseErrorType::OtherError(
1509 "Expected an `elif` or `else` clause, or the end of the `if` statement."
1510 .to_string(),
1511 ),
1512 RecoveryContextKind::Except => ParseErrorType::OtherError(
1513 "Expected an `except` or `finally` clause or the end of the `try` statement."
1514 .to_string(),
1515 ),
1516 RecoveryContextKind::AssignmentTargets => {
1517 if p.current_token_kind().is_keyword() {
1518 ParseErrorType::OtherError(
1519 "The keyword is not allowed as a variable declaration name".to_string(),
1520 )
1521 } else {
1522 ParseErrorType::OtherError("Expected an assignment target".to_string())
1523 }
1524 }
1525 RecoveryContextKind::TypeParams => ParseErrorType::OtherError(
1526 "Expected a type parameter or the end of the type parameter list".to_string(),
1527 ),
1528 RecoveryContextKind::ImportFromAsNames(parenthesized) => {
1529 if parenthesized.is_yes() {
1530 ParseErrorType::OtherError("Expected an import name or a ')'".to_string())
1531 } else {
1532 ParseErrorType::OtherError("Expected an import name".to_string())
1533 }
1534 }
1535 RecoveryContextKind::ImportNames => {
1536 ParseErrorType::OtherError("Expected an import name".to_string())
1537 }
1538 RecoveryContextKind::Slices => ParseErrorType::OtherError(
1539 "Expected an expression or the end of the slice list".to_string(),
1540 ),
1541 RecoveryContextKind::ListElements => {
1542 ParseErrorType::OtherError("Expected an expression or a ']'".to_string())
1543 }
1544 RecoveryContextKind::SetElements | RecoveryContextKind::DictElements => {
1545 ParseErrorType::OtherError("Expected an expression or a '}'".to_string())
1546 }
1547 RecoveryContextKind::TupleElements(parenthesized) => {
1548 if parenthesized.is_yes() {
1549 ParseErrorType::OtherError("Expected an expression or a ')'".to_string())
1550 } else {
1551 ParseErrorType::OtherError("Expected an expression".to_string())
1552 }
1553 }
1554 RecoveryContextKind::SequenceMatchPattern(_) => ParseErrorType::OtherError(
1555 "Expected a pattern or the end of the sequence pattern".to_string(),
1556 ),

Callers 2

parse_listMethod · 0.80

Calls 5

is_keywordMethod · 0.80
current_token_kindMethod · 0.80
atMethod · 0.45
to_stringMethod · 0.45
is_yesMethod · 0.45

Tested by

no test coverage detected