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

Method create_error

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

Source from the content-addressed store, hash-verified

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

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