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

Function parse_bitwise_or_expression

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

Source from the content-addressed store, hash-verified

1679}
1680
1681fn parse_bitwise_or_expression(
1682 context: &mut ParserContext,
1683 env: &mut Environment,
1684 tokens: &[Token],
1685 position: &mut usize,
1686) -> Result<Box<dyn Expr>, Box<Diagnostic>> {
1687 let mut lhs = parse_bitwise_xor_expression(context, env, tokens, position)?;
1688
1689 'parse_expr: while is_current_token(tokens, position, TokenKind::BitwiseOr) {
1690 let operator = &tokens[*position];
1691
1692 // Consume `|` token
1693 *position += 1;
1694
1695 let rhs = parse_bitwise_xor_expression(context, env, tokens, position)?;
1696
1697 let lhs_type = lhs.expr_type();
1698 let rhs_type = rhs.expr_type();
1699
1700 let expected_rhs_types = lhs_type.can_perform_or_op_with();
1701
1702 // Can perform this operator between LHS and RHS
1703 if expected_rhs_types.contains(&rhs_type) {
1704 lhs = Box::new(BitwiseExpr {
1705 left: lhs,
1706 operator: BinaryBitwiseOperator::Or,
1707 right: rhs,
1708 result_type: lhs_type.or_op_result_type(&rhs_type),
1709 });
1710
1711 continue 'parse_expr;
1712 }
1713
1714 // Check if RHS expr can be implicit casted to Expected LHS type to make this
1715 // Expression valid
1716 for expected_type in expected_rhs_types.iter() {
1717 if !expected_type.has_implicit_cast_from(&rhs) {
1718 continue;
1719 }
1720
1721 let casting = Box::new(CastExpr {
1722 value: rhs,
1723 result_type: expected_type.clone(),
1724 });
1725
1726 lhs = Box::new(BitwiseExpr {
1727 left: lhs,
1728 operator: BinaryBitwiseOperator::Or,
1729 right: casting,
1730 result_type: lhs_type.or_op_result_type(expected_type),
1731 });
1732
1733 continue 'parse_expr;
1734 }
1735
1736 // Check if LHS expr can be implicit casted to Expected RHS type to make this
1737 // Expression valid
1738 let expected_lhs_types = rhs_type.can_perform_or_op_with();

Callers 1

Calls 9

is_current_tokenFunction · 0.85
expr_typeMethod · 0.80
containsMethod · 0.80
as_boxedMethod · 0.80
with_locationMethod · 0.80
or_op_result_typeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…