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

Function parse_bitwise_and_expression

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

Source from the content-addressed store, hash-verified

1943}
1944
1945fn parse_bitwise_and_expression(
1946 context: &mut ParserContext,
1947 env: &mut Environment,
1948 tokens: &[Token],
1949 position: &mut usize,
1950) -> Result<Box<dyn Expr>, Box<Diagnostic>> {
1951 let mut lhs = parse_comparison_expression(context, env, tokens, position)?;
1952
1953 'parse_expr: while is_current_token(tokens, position, TokenKind::BitwiseAnd) {
1954 let operator = &tokens[*position];
1955
1956 // Consume `&&` token
1957 *position += 1;
1958
1959 let rhs = parse_comparison_expression(context, env, tokens, position)?;
1960
1961 let lhs_type = lhs.expr_type();
1962 let rhs_type = rhs.expr_type();
1963
1964 let expected_rhs_types = lhs_type.can_perform_and_op_with();
1965
1966 // Can perform this operator between LHS and RHS
1967 if expected_rhs_types.contains(&rhs_type) {
1968 lhs = Box::new(BitwiseExpr {
1969 left: lhs,
1970 operator: BinaryBitwiseOperator::And,
1971 right: rhs,
1972 result_type: lhs_type.or_op_result_type(&rhs_type),
1973 });
1974
1975 continue 'parse_expr;
1976 }
1977
1978 // Check if RHS expr can be implicit casted to Expected LHS type to make this
1979 // Expression valid
1980 for expected_type in expected_rhs_types.iter() {
1981 if !expected_type.has_implicit_cast_from(&rhs) {
1982 continue;
1983 }
1984
1985 let casting = Box::new(CastExpr {
1986 value: rhs,
1987 result_type: expected_type.clone(),
1988 });
1989
1990 lhs = Box::new(BitwiseExpr {
1991 left: lhs,
1992 operator: BinaryBitwiseOperator::And,
1993 right: casting,
1994 result_type: lhs_type.or_op_result_type(expected_type),
1995 });
1996
1997 continue 'parse_expr;
1998 }
1999
2000 // Check if LHS expr can be implicit casted to Expected RHS type to make this
2001 // Expression valid
2002 let expected_lhs_types = rhs_type.can_perform_and_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…