(
context: &mut ParserContext,
env: &mut Environment,
tokens: &[Token],
position: &mut usize,
)
| 1857 | } |
| 1858 | |
| 1859 | fn parse_logical_xor_expression( |
| 1860 | context: &mut ParserContext, |
| 1861 | env: &mut Environment, |
| 1862 | tokens: &[Token], |
| 1863 | position: &mut usize, |
| 1864 | ) -> Result<Box<dyn Expr>, Box<Diagnostic>> { |
| 1865 | let mut lhs = parse_bitwise_and_expression(context, env, tokens, position)?; |
| 1866 | |
| 1867 | 'parse_expr: while is_current_token(tokens, position, TokenKind::XorKeyword) { |
| 1868 | let operator = &tokens[*position]; |
| 1869 | |
| 1870 | // Consume`XOR` operator |
| 1871 | *position += 1; |
| 1872 | |
| 1873 | let rhs = parse_bitwise_and_expression(context, env, tokens, position)?; |
| 1874 | |
| 1875 | let lhs_type = lhs.expr_type(); |
| 1876 | let rhs_type = rhs.expr_type(); |
| 1877 | |
| 1878 | let expected_rhs_types = lhs_type.can_perform_logical_xor_op_with(); |
| 1879 | |
| 1880 | // Can perform this operator between LHS and RHS |
| 1881 | if expected_rhs_types.contains(&rhs_type) { |
| 1882 | lhs = Box::new(LogicalExpr { |
| 1883 | left: lhs, |
| 1884 | operator: BinaryLogicalOperator::Xor, |
| 1885 | right: rhs, |
| 1886 | }); |
| 1887 | |
| 1888 | continue 'parse_expr; |
| 1889 | } |
| 1890 | |
| 1891 | // Check if RHS expr can be implicit casted to Expected LHS type to make this |
| 1892 | // Expression valid |
| 1893 | for expected_type in expected_rhs_types.iter() { |
| 1894 | if !expected_type.has_implicit_cast_from(&rhs) { |
| 1895 | continue; |
| 1896 | } |
| 1897 | |
| 1898 | let casting = Box::new(CastExpr { |
| 1899 | value: rhs, |
| 1900 | result_type: expected_type.clone(), |
| 1901 | }); |
| 1902 | |
| 1903 | lhs = Box::new(LogicalExpr { |
| 1904 | left: lhs, |
| 1905 | operator: BinaryLogicalOperator::Xor, |
| 1906 | right: casting, |
| 1907 | }); |
| 1908 | |
| 1909 | continue 'parse_expr; |
| 1910 | } |
| 1911 | |
| 1912 | // Check if LHS expr can be implicit casted to Expected RHS type to make this |
| 1913 | // Expression valid |
| 1914 | let expected_lhs_types = rhs_type.can_perform_logical_xor_op_with(); |
| 1915 | for expected_type in expected_lhs_types.iter() { |
| 1916 | if !expected_type.has_implicit_cast_from(&lhs) { |
no test coverage detected
searching dependent graphs…