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

Function parse_array_value_expression

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

Source from the content-addressed store, hash-verified

3449}
3450
3451fn parse_array_value_expression(
3452 context: &mut ParserContext,
3453 env: &mut Environment,
3454 tokens: &[Token],
3455 position: &mut usize,
3456) -> Result<Box<dyn Expr>, Box<Diagnostic>> {
3457 // Consume the Optional Array keyword
3458 if *position < tokens.len() && tokens[*position].kind == TokenKind::Array {
3459 // Consume Array keyword
3460 *position += 1;
3461
3462 // Make sure Array keyword followed by [
3463 if *position >= tokens.len() || tokens[*position].kind != TokenKind::LeftBracket {
3464 return Err(Diagnostic::error("Expect `[` after `ARRAY` keyword")
3465 .with_location(calculate_safe_location(tokens, *position))
3466 .add_help("Try to add '[' after `ARRAY` keyword")
3467 .as_boxed());
3468 }
3469 }
3470
3471 // Consume Left Bracket `[`
3472 *position += 1;
3473
3474 // Parse array values
3475 let mut array_values: Vec<Box<dyn Expr>> = vec![];
3476 let mut array_data_type: Box<dyn DataType> = Box::new(AnyType);
3477 while *position < tokens.len() && tokens[*position].kind != TokenKind::RightBracket {
3478 let value = parse_expression(context, env, tokens, position)?;
3479 let value_type = value.expr_type();
3480 if !value_type.equals(&array_data_type) {
3481 return Err(Diagnostic::error("Expect Array values to have same types")
3482 .with_location(calculate_safe_location(tokens, *position))
3483 .as_boxed());
3484 }
3485
3486 array_data_type = value_type;
3487 array_values.push(value);
3488
3489 if *position < tokens.len() && tokens[*position].kind == TokenKind::Comma {
3490 *position += 1;
3491 } else {
3492 break;
3493 }
3494 }
3495
3496 // Make sure Array values end with by ]
3497 if *position >= tokens.len() || tokens[*position].kind != TokenKind::RightBracket {
3498 return Err(Diagnostic::error("Expect `]` at the end of array values")
3499 .with_location(calculate_safe_location(tokens, *position))
3500 .add_help("Try to add ']' at the end of array values")
3501 .as_boxed());
3502 }
3503
3504 // Consume Right Bracket `]`
3505 *position += 1;
3506
3507 Ok(Box::new(ArrayExpr {
3508 values: array_values,

Callers 1

parse_primary_expressionFunction · 0.85

Calls 8

calculate_safe_locationFunction · 0.85
parse_expressionFunction · 0.85
as_boxedMethod · 0.80
add_helpMethod · 0.80
with_locationMethod · 0.80
expr_typeMethod · 0.80
lenMethod · 0.45
equalsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…