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

Function parse_logical_or_expression

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

Source from the content-addressed store, hash-verified

1507}
1508
1509fn parse_logical_or_expression(
1510 context: &mut ParserContext,
1511 env: &mut Environment,
1512 tokens: &[Token],
1513 position: &mut usize,
1514) -> Result<Box<dyn Expr>, Box<Diagnostic>> {
1515 let mut lhs = parse_logical_and_expression(context, env, tokens, position)?;
1516
1517 'parse_expr: while is_logical_or_operator(tokens, position) {
1518 let operator = &tokens[*position];
1519
1520 // Consume`OR` operator
1521 *position += 1;
1522
1523 let rhs = parse_logical_and_expression(context, env, tokens, position)?;
1524
1525 let lhs_type = lhs.expr_type();
1526 let rhs_type = rhs.expr_type();
1527
1528 let expected_rhs_types = lhs_type.can_perform_logical_or_op_with();
1529
1530 // Can perform this operator between LHS and RHS
1531 if expected_rhs_types.contains(&rhs_type) {
1532 lhs = Box::new(LogicalExpr {
1533 left: lhs,
1534 operator: BinaryLogicalOperator::Or,
1535 right: rhs,
1536 });
1537
1538 continue 'parse_expr;
1539 }
1540
1541 // Check if RHS expr can be implicit casted to Expected LHS type to make this
1542 // Expression valid
1543 for expected_type in expected_rhs_types {
1544 if !expected_type.has_implicit_cast_from(&lhs) {
1545 continue;
1546 }
1547
1548 let casting = Box::new(CastExpr {
1549 value: rhs,
1550 result_type: expected_type.clone(),
1551 });
1552
1553 lhs = Box::new(LogicalExpr {
1554 left: lhs,
1555 operator: BinaryLogicalOperator::Or,
1556 right: casting,
1557 });
1558
1559 continue 'parse_expr;
1560 }
1561
1562 // Check if LHS expr can be implicit casted to Expected RHS type to make this
1563 // Expression valid
1564 let expected_lhs_types = rhs_type.can_perform_logical_or_op_with();
1565 for expected_type in expected_lhs_types.iter() {
1566 if !expected_type.has_implicit_cast_from(&lhs) {

Callers 1

parse_in_expressionFunction · 0.85

Calls 8

is_logical_or_operatorFunction · 0.85
expr_typeMethod · 0.80
containsMethod · 0.80
as_boxedMethod · 0.80
with_locationMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…