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

Function parse_contained_by_expression

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

Source from the content-addressed store, hash-verified

2087}
2088
2089fn parse_contained_by_expression(
2090 context: &mut ParserContext,
2091 env: &mut Environment,
2092 tokens: &[Token],
2093 position: &mut usize,
2094) -> Result<Box<dyn Expr>, Box<Diagnostic>> {
2095 let lhs = parse_bitwise_shift_expression(context, env, tokens, position)?;
2096
2097 if is_current_token(tokens, position, TokenKind::ArrowRightAt) {
2098 let operator = &tokens[*position];
2099
2100 // Consume `<@` token
2101 *position += 1;
2102
2103 let rhs = parse_bitwise_shift_expression(context, env, tokens, position)?;
2104
2105 let lhs_type = lhs.expr_type();
2106 let rhs_type = rhs.expr_type();
2107
2108 let expected_lhs_types = rhs_type.can_perform_contains_op_with();
2109
2110 // Can perform this operator between LHS and RHS
2111 if expected_lhs_types.contains(&lhs_type) {
2112 return Ok(Box::new(ContainedByExpr {
2113 left: lhs,
2114 right: rhs,
2115 }));
2116 }
2117
2118 // Check if can perform the operator with additional implicit casting
2119 for expected_type in expected_lhs_types.iter() {
2120 if !expected_type.has_implicit_cast_from(&lhs) {
2121 continue;
2122 }
2123
2124 let casting = Box::new(CastExpr {
2125 value: lhs,
2126 result_type: expected_type.clone(),
2127 });
2128
2129 return Ok(Box::new(ContainedByExpr {
2130 left: casting,
2131 right: rhs,
2132 }));
2133 }
2134
2135 // Return error if this operator can't be performed even with implicit cast
2136 return Err(Diagnostic::error(&format!(
2137 "Operator `<@` can't be performed between types `{lhs_type}` and `{rhs_type}`"
2138 ))
2139 .with_location(operator.location)
2140 .as_boxed());
2141 }
2142
2143 Ok(lhs)
2144}
2145
2146fn parse_bitwise_shift_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…