(
context: &mut ParserContext,
env: &mut Environment,
tokens: &[Token],
position: &mut usize,
)
| 3664 | } |
| 3665 | |
| 3666 | fn 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 | |
| 3722 | fn parse_global_variable_expression( |
| 3723 | env: &mut Environment, |
no test coverage detected
searching dependent graphs…