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

Method create_error

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

Source from the content-addressed store, hash-verified

1514 }
1515
1516 fn create_error(self, p: &Parser) -> ParseErrorType {
1517 match self {
1518 RecoveryContextKind::ModuleStatements | RecoveryContextKind::BlockStatements => {
1519 if p.at(TokenKind::Indent) {
1520 ParseErrorType::UnexpectedIndentation
1521 } else {
1522 ParseErrorType::OtherError("Expected a statement".to_string())
1523 }
1524 }
1525 RecoveryContextKind::Elif => ParseErrorType::OtherError(
1526 "Expected an `elif` or `else` clause, or the end of the `if` statement."
1527 .to_string(),
1528 ),
1529 RecoveryContextKind::Except => ParseErrorType::OtherError(
1530 "Expected an `except` or `finally` clause or the end of the `try` statement."
1531 .to_string(),
1532 ),
1533 RecoveryContextKind::AssignmentTargets => {
1534 if p.current_token_kind().is_keyword() {
1535 ParseErrorType::OtherError(
1536 "The keyword is not allowed as a variable declaration name".to_string(),
1537 )
1538 } else {
1539 ParseErrorType::OtherError("Expected an assignment target".to_string())
1540 }
1541 }
1542 RecoveryContextKind::TypeParams => ParseErrorType::OtherError(
1543 "Expected a type parameter or the end of the type parameter list".to_string(),
1544 ),
1545 RecoveryContextKind::ImportFromAsNames(parenthesized) => {
1546 if parenthesized.is_yes() {
1547 ParseErrorType::OtherError("Expected an import name or a ')'".to_string())
1548 } else {
1549 ParseErrorType::OtherError("Expected an import name".to_string())
1550 }
1551 }
1552 RecoveryContextKind::ImportNames => {
1553 ParseErrorType::OtherError("Expected an import name".to_string())
1554 }
1555 RecoveryContextKind::Slices => ParseErrorType::OtherError(
1556 "Expected an expression or the end of the slice list".to_string(),
1557 ),
1558 RecoveryContextKind::ListElements => {
1559 ParseErrorType::OtherError("Expected an expression or a ']'".to_string())
1560 }
1561 RecoveryContextKind::SetElements | RecoveryContextKind::DictElements => {
1562 ParseErrorType::OtherError("Expected an expression or a '}'".to_string())
1563 }
1564 RecoveryContextKind::TupleElements(parenthesized) => {
1565 if parenthesized.is_yes() {
1566 ParseErrorType::OtherError("Expected an expression or a ')'".to_string())
1567 } else {
1568 ParseErrorType::OtherError("Expected an expression".to_string())
1569 }
1570 }
1571 RecoveryContextKind::SequenceMatchPattern(_) => ParseErrorType::OtherError(
1572 "Expected a pattern or the end of the sequence pattern".to_string(),
1573 ),

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