MCPcopy Create free account
hub / github.com/AmrDeveloper/GQL / parse_contains_expression

Function parse_contains_expression

crates/gitql-parser/src/parser.rs:2032–2087  ·  view source on GitHub ↗
(
    context: &mut ParserContext,
    env: &mut Environment,
    tokens: &[Token],
    position: &mut usize,
)

Source from the content-addressed store, hash-verified

2030}
2031
2032pub(crate) fn parse_contains_expression(
2033 context: &mut ParserContext,
2034 env: &mut Environment,
2035 tokens: &[Token],
2036 position: &mut usize,
2037) -> Result<Box<dyn Expr>, Box<Diagnostic>> {
2038 let lhs = parse_contained_by_expression(context, env, tokens, position)?;
2039
2040 if is_current_token(tokens, position, TokenKind::AtRightArrow) {
2041 let operator = &tokens[*position];
2042
2043 // Consume `@>` token
2044 *position += 1;
2045
2046 let rhs = parse_contained_by_expression(context, env, tokens, position)?;
2047
2048 let lhs_type = lhs.expr_type();
2049 let rhs_type = rhs.expr_type();
2050
2051 let expected_rhs_types = lhs_type.can_perform_contains_op_with();
2052
2053 // Can perform this operator between LHS and RHS
2054 if expected_rhs_types.contains(&rhs_type) {
2055 return Ok(Box::new(ContainsExpr {
2056 left: lhs,
2057 right: rhs,
2058 }));
2059 }
2060
2061 // Check if can perform the operator with additional implicit casting
2062 for expected_type in expected_rhs_types.iter() {
2063 if !expected_type.has_implicit_cast_from(&rhs) {
2064 continue;
2065 }
2066
2067 let casting = Box::new(CastExpr {
2068 value: rhs,
2069 result_type: expected_type.clone(),
2070 });
2071
2072 return Ok(Box::new(ContainsExpr {
2073 left: lhs,
2074 right: casting,
2075 }));
2076 }
2077
2078 // Return error if this operator can't be performed even with implicit cast
2079 return Err(Diagnostic::error(&format!(
2080 "Operator `@>` can't be performed between types `{lhs_type}` and `{rhs_type}`"
2081 ))
2082 .with_location(operator.location)
2083 .as_boxed());
2084 }
2085
2086 Ok(lhs)
2087}
2088
2089fn parse_contained_by_expression(

Callers 1

Calls 8

is_current_tokenFunction · 0.85
expr_typeMethod · 0.80
containsMethod · 0.80
as_boxedMethod · 0.80
with_locationMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…