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

Function parse_glob_expression

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

Source from the content-addressed store, hash-verified

92}
93
94pub(crate) fn parse_glob_expression(
95 context: &mut ParserContext,
96 env: &mut Environment,
97 tokens: &[Token],
98 position: &mut usize,
99) -> Result<Box<dyn Expr>, Box<Diagnostic>> {
100 let lhs = parse_cast_operator_expression(context, env, tokens, position)?;
101
102 if is_current_token(tokens, position, TokenKind::Glob) {
103 let glob_location = tokens[*position].location;
104
105 // Consume `GLOB` Token
106 *position += 1;
107
108 let pattern = parse_cast_operator_expression(context, env, tokens, position)?;
109
110 let lhs_type = lhs.expr_type();
111 let rhs_type = pattern.expr_type();
112
113 // Can perform this operator between LHS and RHS
114 let expected_rhs_types = lhs_type.can_perform_glob_op_with();
115 if expected_rhs_types.contains(&rhs_type) {
116 return Ok(Box::new(GlobExpr {
117 input: lhs,
118 pattern,
119 }));
120 }
121
122 // Check if RHS expr can be implicit casted to Expected LHS type to make this
123 // Expression valid
124 for expected_type in expected_rhs_types.iter() {
125 if !expected_type.has_implicit_cast_from(&pattern) {
126 continue;
127 }
128
129 let casting = Box::new(CastExpr {
130 value: pattern,
131 result_type: expected_type.clone(),
132 });
133
134 return Ok(Box::new(GlobExpr {
135 input: lhs,
136 pattern: casting,
137 }));
138 }
139
140 // Return error if this operator can't be performed even with implicit cast
141 return Err(Diagnostic::error(&format!(
142 "Operator `GLOB` can't be performed between types `{lhs_type}` and `{rhs_type}`"
143 ))
144 .with_location(glob_location)
145 .as_boxed());
146 }
147
148 Ok(lhs)
149}
150
151pub(crate) fn parse_regex_expression(

Callers 1

parse_like_expressionFunction · 0.85

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…