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

Function graph_expression

graphlite/src/ast/parser.rs:3347–3399  ·  view source on GitHub ↗

Parse graph expression for session context

(tokens: &[Token])

Source from the content-addressed store, hash-verified

3345
3346/// Parse graph expression for session context
3347fn graph_expression(tokens: &[Token]) -> IResult<&[Token], GraphExpression> {
3348 log::debug!(
3349 "graph_expression called with tokens: {:?}",
3350 tokens.get(0..3).unwrap_or(&[])
3351 );
3352
3353 // Parse union operations with precedence
3354 fn union_expr(tokens: &[Token]) -> IResult<&[Token], GraphExpression> {
3355 let (tokens, left) = primary_graph_expr(tokens)?;
3356
3357 // Check for UNION operators
3358 let mut current = left;
3359 let mut remaining = tokens;
3360
3361 while let Ok((tokens_after_union, _)) = expect_token(Token::Union)(remaining) {
3362 let (tokens_after_all, union_all) = opt(expect_token(Token::All))(tokens_after_union)?;
3363 let all = union_all.is_some();
3364 let (tokens_after_right, right) = primary_graph_expr(tokens_after_all)?;
3365
3366 current = GraphExpression::Union {
3367 left: Box::new(current),
3368 right: Box::new(right),
3369 all,
3370 };
3371 remaining = tokens_after_right;
3372 }
3373
3374 Ok((remaining, current))
3375 }
3376
3377 // Parse primary graph expressions (non-union)
3378 fn primary_graph_expr(tokens: &[Token]) -> IResult<&[Token], GraphExpression> {
3379 alt((
3380 // Parenthesized expressions
3381 delimited(
3382 expect_token(Token::LeftParen),
3383 union_expr,
3384 expect_token(Token::RightParen),
3385 ),
3386 // parameter or catalog_path
3387 map(parameter_or_catalog_path, |path_or_param| {
3388 log::debug!("graph_expression parsed catalog path: {:?}", path_or_param);
3389 GraphExpression::Reference(path_or_param)
3390 }),
3391 ))(tokens)
3392 }
3393
3394 let result = union_expr(tokens);
3395 if result.is_err() {
3396 log::debug!("graph_expression parsing failed: {:?}", result);
3397 }
3398 result
3399}
3400
3401/// Parse parameter: $identifier (returns Parameter struct for expressions)
3402fn parameter(tokens: &[Token]) -> IResult<&[Token], Parameter> {

Callers

nothing calls this directly

Calls 1

union_exprFunction · 0.85

Tested by

no test coverage detected