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

Method create_error

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

Source from the content-addressed store, hash-verified

1448 }
1449
1450 fn create_error(self, p: &Parser) -> ParseErrorType {
1451 match self {
1452 RecoveryContextKind::ModuleStatements | RecoveryContextKind::BlockStatements => {
1453 if p.at(TokenKind::Indent) {
1454 ParseErrorType::UnexpectedIndentation
1455 } else {
1456 ParseErrorType::OtherError("Expected a statement".to_string())
1457 }
1458 }
1459 RecoveryContextKind::Elif => ParseErrorType::OtherError(
1460 "Expected an `elif` or `else` clause, or the end of the `if` statement."
1461 .to_string(),
1462 ),
1463 RecoveryContextKind::Except => ParseErrorType::OtherError(
1464 "Expected an `except` or `finally` clause or the end of the `try` statement."
1465 .to_string(),
1466 ),
1467 RecoveryContextKind::AssignmentTargets => {
1468 if p.current_token_kind().is_keyword() {
1469 ParseErrorType::OtherError(
1470 "The keyword is not allowed as a variable declaration name".to_string(),
1471 )
1472 } else {
1473 ParseErrorType::OtherError("Expected an assignment target".to_string())
1474 }
1475 }
1476 RecoveryContextKind::TypeParams => ParseErrorType::OtherError(
1477 "Expected a type parameter or the end of the type parameter list".to_string(),
1478 ),
1479 RecoveryContextKind::ImportFromAsNames(parenthesized) => {
1480 if parenthesized.is_yes() {
1481 ParseErrorType::OtherError("Expected an import name or a ')'".to_string())
1482 } else {
1483 ParseErrorType::OtherError("Expected an import name".to_string())
1484 }
1485 }
1486 RecoveryContextKind::ImportNames => {
1487 ParseErrorType::OtherError("Expected an import name".to_string())
1488 }
1489 RecoveryContextKind::Slices => ParseErrorType::OtherError(
1490 "Expected an expression or the end of the slice list".to_string(),
1491 ),
1492 RecoveryContextKind::ListElements => {
1493 ParseErrorType::OtherError("Expected an expression or a ']'".to_string())
1494 }
1495 RecoveryContextKind::SetElements | RecoveryContextKind::DictElements => {
1496 ParseErrorType::OtherError("Expected an expression or a '}'".to_string())
1497 }
1498 RecoveryContextKind::TupleElements(parenthesized) => {
1499 if parenthesized.is_yes() {
1500 ParseErrorType::OtherError("Expected an expression or a ')'".to_string())
1501 } else {
1502 ParseErrorType::OtherError("Expected an expression".to_string())
1503 }
1504 }
1505 RecoveryContextKind::SequenceMatchPattern(_) => ParseErrorType::OtherError(
1506 "Expected a pattern or the end of the sequence pattern".to_string(),
1507 ),

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