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