Parses the body of the given [`Clause`]. This could either be a single statement that's on the same line as the clause header or an indented block.
(&mut self, parent_clause: Clause)
| 3106 | /// This could either be a single statement that's on the same line as the |
| 3107 | /// clause header or an indented block. |
| 3108 | fn parse_body(&mut self, parent_clause: Clause) -> Suite { |
| 3109 | // Note: The test cases in this method chooses a clause at random to test |
| 3110 | // the error logic. |
| 3111 | |
| 3112 | let newline_range = self.current_token_range(); |
| 3113 | if self.eat(TokenKind::Newline) { |
| 3114 | if self.at(TokenKind::Indent) { |
| 3115 | return self.parse_block(); |
| 3116 | } |
| 3117 | // test_err clause_expect_indented_block |
| 3118 | // # Here, the error is highlighted at the `pass` token |
| 3119 | // if True: |
| 3120 | // pass |
| 3121 | // # The parser is at the end of the program, so let's highlight |
| 3122 | // # at the newline token after `:` |
| 3123 | // if True: |
| 3124 | self.add_error( |
| 3125 | ParseErrorType::OtherError(format!( |
| 3126 | "Expected an indented block after {parent_clause}" |
| 3127 | )), |
| 3128 | if self.current_token_range().is_empty() { |
| 3129 | newline_range |
| 3130 | } else { |
| 3131 | self.current_token_range() |
| 3132 | }, |
| 3133 | ); |
| 3134 | } else { |
| 3135 | if self.at_simple_stmt() { |
| 3136 | return self.parse_simple_statements(); |
| 3137 | } |
| 3138 | // test_err clause_expect_single_statement |
| 3139 | // if True: if True: pass |
| 3140 | self.add_error( |
| 3141 | ParseErrorType::OtherError("Expected a simple statement".to_string()), |
| 3142 | self.current_token_range(), |
| 3143 | ); |
| 3144 | } |
| 3145 | |
| 3146 | Suite::new() |
| 3147 | } |
| 3148 | |
| 3149 | /// Parses a block of statements. |
| 3150 | /// |
no test coverage detected