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

Function parse_in_expression

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

Source from the content-addressed store, hash-verified

1437}
1438
1439fn parse_in_expression(
1440 context: &mut ParserContext,
1441 env: &mut Environment,
1442 tokens: &[Token],
1443 position: &mut usize,
1444) -> Result<Box<dyn Expr>, Box<Diagnostic>> {
1445 let expression = parse_logical_or_expression(context, env, tokens, position)?;
1446
1447 // Consume NOT if current token is `NOT` and next one is `IN`
1448 let has_not_keyword = if *position < tokens.len() - 1
1449 && tokens[*position].kind == TokenKind::Not
1450 && tokens[*position + 1].kind == TokenKind::In
1451 {
1452 *position += 1;
1453 true
1454 } else {
1455 false
1456 };
1457
1458 if is_current_token(tokens, position, TokenKind::In) {
1459 let in_location = tokens[*position].location;
1460
1461 // Consume `IN` keyword
1462 *position += 1;
1463
1464 if !is_current_token(tokens, position, TokenKind::LeftParen) {
1465 return Err(Diagnostic::error("Expects `(` After `IN` Keyword")
1466 .with_location(in_location)
1467 .as_boxed());
1468 }
1469
1470 let values =
1471 parse_zero_or_more_values_with_comma_between(context, env, tokens, position, "IN")?;
1472
1473 // Optimize the Expression if the number of values in the list is 0
1474 if values.is_empty() {
1475 let is_true = has_not_keyword;
1476 return Ok(Box::new(BooleanExpr { is_true }));
1477 }
1478
1479 let values_type_result = check_all_values_are_same_type(&values);
1480 if values_type_result.is_none() {
1481 return Err(Diagnostic::error(
1482 "Expects values between `(` and `)` to have the same type",
1483 )
1484 .with_location(in_location)
1485 .as_boxed());
1486 }
1487
1488 // Check that argument and values has the same type
1489 let values_type = values_type_result.unwrap();
1490 if !values_type.is_any() && !expression.expr_type().equals(&values_type) {
1491 return Err(Diagnostic::error(
1492 "Argument and Values of In Expression must have the same type",
1493 )
1494 .with_location(in_location)
1495 .as_boxed());
1496 }

Callers 1

parse_is_null_expressionFunction · 0.85

Calls 11

is_current_tokenFunction · 0.85
as_boxedMethod · 0.80
with_locationMethod · 0.80
is_anyMethod · 0.80
expr_typeMethod · 0.80
lenMethod · 0.45
is_emptyMethod · 0.45
equalsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…