MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / extract_variable_references

Function extract_variable_references

graphlite/src/ast/validator.rs:2262–2311  ·  view source on GitHub ↗

Extract variable references from an expression (helper for WHERE validation)

(
    expr: &Expression,
    variables: &mut std::collections::HashSet<String>,
)

Source from the content-addressed store, hash-verified

2260
2261/// Extract variable references from an expression (helper for WHERE validation)
2262fn extract_variable_references(
2263 expr: &Expression,
2264 variables: &mut std::collections::HashSet<String>,
2265) {
2266 match expr {
2267 Expression::Variable(var) => {
2268 variables.insert(var.name.clone());
2269 }
2270 Expression::PropertyAccess(prop_access) => {
2271 variables.insert(prop_access.property.clone());
2272 }
2273 Expression::Binary(binary_expr) => {
2274 extract_variable_references(&binary_expr.left, variables);
2275 extract_variable_references(&binary_expr.right, variables);
2276 }
2277 Expression::Unary(unary_expr) => {
2278 extract_variable_references(&unary_expr.expression, variables);
2279 }
2280 Expression::FunctionCall(func_call) => {
2281 for arg in &func_call.arguments {
2282 extract_variable_references(arg, variables);
2283 }
2284 }
2285 Expression::Case(case_expr) => match &case_expr.case_type {
2286 crate::ast::CaseType::Simple(simple) => {
2287 extract_variable_references(&simple.test_expression, variables);
2288 for branch in &simple.when_branches {
2289 for when_val in &branch.when_values {
2290 extract_variable_references(when_val, variables);
2291 }
2292 extract_variable_references(&branch.then_expression, variables);
2293 }
2294 if let Some(else_expr) = &simple.else_expression {
2295 extract_variable_references(else_expr, variables);
2296 }
2297 }
2298 crate::ast::CaseType::Searched(searched) => {
2299 for branch in &searched.when_branches {
2300 extract_variable_references(&branch.condition, variables);
2301 extract_variable_references(&branch.then_expression, variables);
2302 }
2303 if let Some(else_expr) = &searched.else_expression {
2304 extract_variable_references(else_expr, variables);
2305 }
2306 }
2307 },
2308 // For other expression types (literals, etc.), no variables to extract
2309 _ => {}
2310 }
2311}
2312
2313/// Validate YIELD clause
2314fn validate_yield_clause(yield_clause: &YieldClause, errors: &mut Vec<ValidationError>) {

Calls 2

cloneMethod · 0.80
insertMethod · 0.45

Tested by

no test coverage detected