Parse a procedural SQL body into a `ProceduralBlock`. Input: raw SQL text starting with `BEGIN` and ending with `END`.
(input: &str)
| 18 | /// |
| 19 | /// Input: raw SQL text starting with `BEGIN` and ending with `END`. |
| 20 | pub fn parse_block(input: &str) -> Result<ProceduralBlock, ProceduralError> { |
| 21 | let tokens = super::tokenizer::tokenize(input)?; |
| 22 | let mut pos = 0; |
| 23 | |
| 24 | skip_token(&tokens, &mut pos, &Token::Begin)?; |
| 25 | |
| 26 | let statements = parse_statements(&tokens, &mut pos)?; |
| 27 | |
| 28 | let exception_handlers = if pos < tokens.len() && tokens[pos] == Token::Exception { |
| 29 | exception::parse_exception_handlers(&tokens, &mut pos)? |
| 30 | } else { |
| 31 | Vec::new() |
| 32 | }; |
| 33 | |
| 34 | expect_token(&tokens, &mut pos, &Token::End)?; |
| 35 | skip_if(&tokens, &mut pos, &Token::Semicolon); |
| 36 | |
| 37 | Ok(ProceduralBlock { |
| 38 | statements, |
| 39 | exception_handlers, |
| 40 | }) |
| 41 | } |
| 42 | |
| 43 | /// Parse a sequence of statements until we hit END, ELSE, ELSIF, EXCEPTION, or end of tokens. |
| 44 | pub(crate) fn parse_statements( |