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

Function parse_logical_and_expression

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

Source from the content-addressed store, hash-verified

1593}
1594
1595fn parse_logical_and_expression(
1596 context: &mut ParserContext,
1597 env: &mut Environment,
1598 tokens: &[Token],
1599 position: &mut usize,
1600) -> Result<Box<dyn Expr>, Box<Diagnostic>> {
1601 let mut lhs = parse_bitwise_or_expression(context, env, tokens, position)?;
1602
1603 'parse_expr: while is_logical_and_operator(tokens, position) {
1604 let operator = &tokens[*position];
1605
1606 // Consume`AND` operator
1607 *position += 1;
1608
1609 let rhs = parse_bitwise_or_expression(context, env, tokens, position)?;
1610
1611 let lhs_type = lhs.expr_type();
1612 let rhs_type = rhs.expr_type();
1613
1614 let expected_rhs_types = lhs_type.can_perform_logical_and_op_with();
1615
1616 // Can perform this operator between LHS and RHS
1617 if expected_rhs_types.contains(&rhs_type) {
1618 lhs = Box::new(LogicalExpr {
1619 left: lhs,
1620 operator: BinaryLogicalOperator::And,
1621 right: rhs,
1622 });
1623
1624 continue 'parse_expr;
1625 }
1626
1627 // Check if RHS expr can be implicit casted to Expected LHS type to make this
1628 // Expression valid
1629 for expected_type in expected_rhs_types.iter() {
1630 if !expected_type.has_implicit_cast_from(&rhs) {
1631 continue;
1632 }
1633
1634 let casting = Box::new(CastExpr {
1635 value: rhs,
1636 result_type: expected_type.clone(),
1637 });
1638
1639 lhs = Box::new(LogicalExpr {
1640 left: lhs,
1641 operator: BinaryLogicalOperator::And,
1642 right: casting,
1643 });
1644
1645 continue 'parse_expr;
1646 }
1647
1648 // Check if LHS expr can be implicit casted to Expected RHS type to make this
1649 // Expression valid
1650 let expected_lhs_types = rhs_type.can_perform_logical_and_op_with();
1651 for expected_type in expected_lhs_types.iter() {
1652 if !expected_type.has_implicit_cast_from(&lhs) {

Callers 1

Calls 8

is_logical_and_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…