`IF cond THEN ... [ELSIF cond THEN ...] [ELSE ...] END IF;`
(tokens: &[Token], pos: &mut usize)
| 126 | |
| 127 | /// `IF cond THEN ... [ELSIF cond THEN ...] [ELSE ...] END IF;` |
| 128 | fn parse_if(tokens: &[Token], pos: &mut usize) -> Result<Statement, ProceduralError> { |
| 129 | *pos += 1; |
| 130 | let condition = collect_sql_until(tokens, pos, &[Token::Then])?; |
| 131 | expect_token(tokens, pos, &Token::Then)?; |
| 132 | let then_block = super::parse_statements(tokens, pos)?; |
| 133 | |
| 134 | let mut elsif_branches = Vec::new(); |
| 135 | while matches!(tokens.get(*pos), Some(Token::Elsif)) { |
| 136 | *pos += 1; |
| 137 | let cond = collect_sql_until(tokens, pos, &[Token::Then])?; |
| 138 | expect_token(tokens, pos, &Token::Then)?; |
| 139 | let body = super::parse_statements(tokens, pos)?; |
| 140 | elsif_branches.push(ElsIfBranch { |
| 141 | condition: cond, |
| 142 | body, |
| 143 | }); |
| 144 | } |
| 145 | |
| 146 | let else_block = if matches!(tokens.get(*pos), Some(Token::Else)) { |
| 147 | *pos += 1; |
| 148 | Some(super::parse_statements(tokens, pos)?) |
| 149 | } else { |
| 150 | None |
| 151 | }; |
| 152 | |
| 153 | expect_token(tokens, pos, &Token::EndIf)?; |
| 154 | skip_if(tokens, pos, &Token::Semicolon); |
| 155 | |
| 156 | Ok(Statement::If { |
| 157 | condition, |
| 158 | then_block, |
| 159 | elsif_branches, |
| 160 | else_block, |
| 161 | }) |
| 162 | } |
| 163 | |
| 164 | /// `WHILE cond LOOP ... END LOOP;` |
| 165 | fn parse_while(tokens: &[Token], pos: &mut usize) -> Result<Statement, ProceduralError> { |
no test coverage detected