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

Function parse_factor_expression

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

Source from the content-addressed store, hash-verified

2467}
2468
2469fn parse_factor_expression(
2470 context: &mut ParserContext,
2471 env: &mut Environment,
2472 tokens: &[Token],
2473 position: &mut usize,
2474) -> Result<Box<dyn Expr>, Box<Diagnostic>> {
2475 let mut lhs = parse_like_expression(context, env, tokens, position)?;
2476
2477 'parse_expr: while is_factor_operator(tokens, position) {
2478 let operator = &tokens[*position];
2479
2480 // Consume `*`, '/`, '%' or '^` operator
2481 *position += 1;
2482
2483 let rhs = parse_like_expression(context, env, tokens, position)?;
2484
2485 let lhs_type = lhs.expr_type();
2486 let rhs_type = rhs.expr_type();
2487
2488 // Parse and Check sides for `*` operator
2489 if operator.kind == TokenKind::Star {
2490 let expected_rhs_types = lhs_type.can_perform_mul_op_with();
2491
2492 // Can perform this operator between LHS and RHS
2493 if expected_rhs_types.contains(&rhs_type) {
2494 lhs = Box::new(ArithmeticExpr {
2495 left: lhs,
2496 operator: ArithmeticOperator::Star,
2497 right: rhs,
2498 result_type: lhs_type.mul_op_result_type(&rhs_type),
2499 });
2500
2501 continue 'parse_expr;
2502 }
2503
2504 // Check if RHS expr can be implicit casted to Expected LHS type to make this
2505 // Expression valid
2506 for expected_type in expected_rhs_types.iter() {
2507 if !expected_type.has_implicit_cast_from(&rhs) {
2508 continue;
2509 }
2510
2511 let casting = Box::new(CastExpr {
2512 value: rhs,
2513 result_type: expected_type.clone(),
2514 });
2515
2516 lhs = Box::new(ArithmeticExpr {
2517 left: lhs,
2518 operator: ArithmeticOperator::Star,
2519 right: casting,
2520 result_type: lhs_type.mul_op_result_type(expected_type),
2521 });
2522
2523 continue 'parse_expr;
2524 }
2525
2526 // Check if LHS expr can be implicit casted to Expected RHS type to make this

Callers 1

parse_term_expressionFunction · 0.85

Calls 15

parse_like_expressionFunction · 0.85
is_factor_operatorFunction · 0.85
expr_typeMethod · 0.80
containsMethod · 0.80
as_boxedMethod · 0.80
with_locationMethod · 0.80
mul_op_result_typeMethod · 0.45
div_op_result_typeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…