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

Function parse_qualify_statement

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

Source from the content-addressed store, hash-verified

1141}
1142
1143fn parse_qualify_statement(
1144 context: &mut ParserContext,
1145 env: &mut Environment,
1146 tokens: &[Token],
1147 position: &mut usize,
1148) -> Result<Statement, Box<Diagnostic>> {
1149 // Consume `QUALIFY` token
1150 *position += 1;
1151
1152 if *position >= tokens.len() {
1153 return Err(
1154 Diagnostic::error("Expect expression after `QUALIFY` keyword")
1155 .add_help("Try to add boolean expression after `QUALIFY` keyword")
1156 .add_note("`QUALIFY` statement expects expression as condition")
1157 .with_location(calculate_safe_location(tokens, *position - 1))
1158 .as_boxed(),
1159 );
1160 }
1161
1162 // Make sure QUALIFY condition expression has boolean type
1163 let condition_location = tokens[*position].location;
1164 let mut condition = parse_expression(context, env, tokens, position)?;
1165
1166 // Make sure that the condition type is boolean, or can implicit cast to boolean.
1167 if !condition.expr_type().is_bool() {
1168 let expected_type: Box<dyn DataType> = Box::new(BoolType);
1169 if !expected_type.has_implicit_cast_from(&condition) {
1170 return Err(Diagnostic::error(&format!(
1171 "Expect `QUALIFY` condition to be type {} but got {}",
1172 "Boolean",
1173 condition.expr_type().literal()
1174 ))
1175 .add_note("`QUALIFY` statement condition must be Boolean")
1176 .with_location(condition_location)
1177 .as_boxed());
1178 }
1179
1180 // Implicit cast the condition to boolean
1181 condition = Box::new(CastExpr {
1182 value: condition,
1183 result_type: expected_type.clone(),
1184 })
1185 }
1186
1187 Ok(Statement::Qualify(QualifyStatement { condition }))
1188}
1189
1190fn parse_limit_statement(
1191 tokens: &[Token],

Callers 1

parse_select_queryFunction · 0.85

Calls 10

calculate_safe_locationFunction · 0.85
parse_expressionFunction · 0.85
as_boxedMethod · 0.80
with_locationMethod · 0.80
add_noteMethod · 0.80
add_helpMethod · 0.80
expr_typeMethod · 0.80
lenMethod · 0.45
is_boolMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…