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