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)
| 3085 | /// This could either be a single statement that's on the same line as the |
| 3086 | /// clause header or an indented block. |
| 3087 | fn parse_body(&mut self, parent_clause: Clause) -> Suite { |
| 3088 | // Note: The test cases in this method chooses a clause at random to test |
| 3089 | // the error logic. |
| 3090 | |
| 3091 | let newline_range = self.current_token_range(); |
| 3092 | if self.eat(TokenKind::Newline) { |
| 3093 | if self.at(TokenKind::Indent) { |
| 3094 | return self.parse_block(); |
| 3095 | } |
| 3096 | // test_err clause_expect_indented_block |
| 3097 | // # Here, the error is highlighted at the `pass` token |
| 3098 | // if True: |
| 3099 | // pass |
| 3100 | // # The parser is at the end of the program, so let's highlight |
| 3101 | // # at the newline token after `:` |
| 3102 | // if True: |
| 3103 | self.add_error( |
| 3104 | ParseErrorType::OtherError(format!( |
| 3105 | "Expected an indented block after {parent_clause}" |
| 3106 | )), |
| 3107 | if self.current_token_range().is_empty() { |
| 3108 | newline_range |
| 3109 | } else { |
| 3110 | self.current_token_range() |
| 3111 | }, |
| 3112 | ); |
| 3113 | } else { |
| 3114 | if self.at_simple_stmt() { |
| 3115 | return self.parse_simple_statements(); |
| 3116 | } |
| 3117 | // test_err clause_expect_single_statement |
| 3118 | // if True: if True: pass |
| 3119 | self.add_error( |
| 3120 | ParseErrorType::OtherError("Expected a simple statement".to_string()), |
| 3121 | self.current_token_range(), |
| 3122 | ); |
| 3123 | } |
| 3124 | |
| 3125 | Suite::new() |
| 3126 | } |
| 3127 | |
| 3128 | /// Parses a block of statements. |
| 3129 | /// |
no test coverage detected