MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / parse_block

Function parse_block

nodedb/src/control/planner/procedural/parser/mod.rs:20–41  ·  view source on GitHub ↗

Parse a procedural SQL body into a `ProceduralBlock`. Input: raw SQL text starting with `BEGIN` and ending with `END`.

(input: &str)

Source from the content-addressed store, hash-verified

18///
19/// Input: raw SQL text starting with `BEGIN` and ending with `END`.
20pub 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.
44pub(crate) fn parse_statements(

Callers 15

parse_simple_returnFunction · 0.85
parse_if_elseFunction · 0.85
parse_if_elsif_elseFunction · 0.85
parse_declare_and_assignFunction · 0.85
parse_while_loopFunction · 0.85
parse_for_loopFunction · 0.85
parse_sql_detectedFunction · 0.85
parse_raiseFunction · 0.85
parse_nested_ifFunction · 0.85

Calls 7

skip_tokenFunction · 0.85
parse_statementsFunction · 0.85
parse_exception_handlersFunction · 0.85
skip_ifFunction · 0.85
expect_tokenFunction · 0.70
tokenizeFunction · 0.50
lenMethod · 0.45

Tested by 15

parse_simple_returnFunction · 0.68
parse_if_elseFunction · 0.68
parse_if_elsif_elseFunction · 0.68
parse_declare_and_assignFunction · 0.68
parse_while_loopFunction · 0.68
parse_for_loopFunction · 0.68
parse_sql_detectedFunction · 0.68
parse_raiseFunction · 0.68
parse_nested_ifFunction · 0.68