Parses the branches of a uniline `IF` statement.
(&mut self, branches: &mut Vec<IfBranchSpan>)
| 1050 | |
| 1051 | /// Parses the branches of a uniline `IF` statement. |
| 1052 | fn parse_if_uniline(&mut self, branches: &mut Vec<IfBranchSpan>) -> Result<()> { |
| 1053 | debug_assert!(!branches.is_empty(), "Caller must populate the guard of the first branch"); |
| 1054 | |
| 1055 | let mut has_else = false; |
| 1056 | let peeked = self.lexer.peek()?; |
| 1057 | match peeked.token { |
| 1058 | Token::Else => has_else = true, |
| 1059 | _ => { |
| 1060 | let stmt = self |
| 1061 | .parse_uniline()? |
| 1062 | .expect("The caller already checked for a non-empty token"); |
| 1063 | branches[0].body.push(stmt); |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | let peeked = self.lexer.peek()?; |
| 1068 | has_else |= peeked.token == Token::Else; |
| 1069 | |
| 1070 | if has_else { |
| 1071 | let else_span = self.lexer.consume_peeked(); |
| 1072 | let expr = Expr::Boolean(BooleanSpan { value: true, pos: else_span.pos }); |
| 1073 | branches.push(IfBranchSpan { guard: expr, body: vec![] }); |
| 1074 | if let Some(stmt) = self.parse_uniline()? { |
| 1075 | branches[1].body.push(stmt); |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | Ok(()) |
| 1080 | } |
| 1081 | |
| 1082 | /// Parses the branches of a multiline `IF` statement. |
| 1083 | fn parse_if_multiline( |
no test coverage detected