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

Function parse_if

nodedb/src/control/planner/procedural/parser/statements.rs:128–162  ·  view source on GitHub ↗

`IF cond THEN ... [ELSIF cond THEN ...] [ELSE ...] END IF;`

(tokens: &[Token], pos: &mut usize)

Source from the content-addressed store, hash-verified

126
127/// `IF cond THEN ... [ELSIF cond THEN ...] [ELSE ...] END IF;`
128fn 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;`
165fn parse_while(tokens: &[Token], pos: &mut usize) -> Result<Statement, ProceduralError> {

Callers 1

parse_statementFunction · 0.85

Calls 5

collect_sql_untilFunction · 0.85
parse_statementsFunction · 0.85
skip_ifFunction · 0.85
expect_tokenFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected