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

Function parse_benchmark_call_expression

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

Source from the content-addressed store, hash-verified

3664}
3665
3666fn parse_benchmark_call_expression(
3667 context: &mut ParserContext,
3668 env: &mut Environment,
3669 tokens: &[Token],
3670 position: &mut usize,
3671) -> Result<Box<dyn Expr>, Box<Diagnostic>> {
3672 // Consume `BENCHMARK` token
3673 *position += 1;
3674
3675 if *position >= tokens.len() || tokens[*position].kind != TokenKind::LeftParen {
3676 return Err(Diagnostic::error("Expect `(` after `Benchmark` keyword")
3677 .with_location(calculate_safe_location(tokens, *position))
3678 .add_help("Try to add '(' right after `Benchmark` keyword")
3679 .as_boxed());
3680 }
3681
3682 // Consume `(` token
3683 *position += 1;
3684
3685 let count = parse_expression(context, env, tokens, position)?;
3686 if !count.expr_type().is_int() {
3687 return Err(
3688 Diagnostic::error("Benchmark expect first argument to be integer")
3689 .with_location(calculate_safe_location(tokens, *position))
3690 .add_help("Try to integer value as first argument, eg: `Benchmark(10, 1 + 1)`")
3691 .as_boxed(),
3692 );
3693 }
3694
3695 if *position >= tokens.len() || tokens[*position].kind != TokenKind::Comma {
3696 return Err(
3697 Diagnostic::error("Expect `,` after Benchmark first argument value")
3698 .with_location(calculate_safe_location(tokens, *position))
3699 .add_help("Make sure you passed two arguments to the Benchmark function")
3700 .as_boxed(),
3701 );
3702 }
3703
3704 // Consume `,` token
3705 *position += 1;
3706
3707 let expression = parse_expression(context, env, tokens, position)?;
3708
3709 if *position >= tokens.len() || tokens[*position].kind != TokenKind::RightParen {
3710 return Err(Diagnostic::error("Expect `)` after `Benchmark` arguments")
3711 .with_location(calculate_safe_location(tokens, *position))
3712 .add_help("Try to add ')` after `Benchmark` arguments")
3713 .as_boxed());
3714 }
3715
3716 // Consume `)` token
3717 *position += 1;
3718
3719 Ok(Box::new(BenchmarkCallExpr { expression, count }))
3720}
3721
3722fn parse_global_variable_expression(
3723 env: &mut Environment,

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
is_intMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…