(
context: &mut ParserContext,
env: &mut Environment,
tokens: &[Token],
position: &mut usize,
)
| 3065 | } |
| 3066 | |
| 3067 | fn parse_between_expression( |
| 3068 | context: &mut ParserContext, |
| 3069 | env: &mut Environment, |
| 3070 | tokens: &[Token], |
| 3071 | position: &mut usize, |
| 3072 | ) -> Result<Box<dyn Expr>, Box<Diagnostic>> { |
| 3073 | let expression = parse_function_call_expression(context, env, tokens, position)?; |
| 3074 | |
| 3075 | // Check for `BETWEEN` or `NOT BETWEEN` |
| 3076 | // <expr> BETWEEN <expr> AND <expr> |
| 3077 | // <expr> NOT BETWEEN <expr> AND <expr> |
| 3078 | if is_current_token(tokens, position, TokenKind::Between) |
| 3079 | || (is_current_token(tokens, position, TokenKind::Not) |
| 3080 | && is_next_token(tokens, position, TokenKind::Between)) |
| 3081 | { |
| 3082 | let has_not_keyword = is_current_token(tokens, position, TokenKind::Not); |
| 3083 | let operator_location = if has_not_keyword { |
| 3084 | // Consume `NOT` and `BETWEEN` keyword |
| 3085 | *position += 2; |
| 3086 | let mut not_location = tokens[*position - 2].location; |
| 3087 | let between_location = tokens[*position - 1].location; |
| 3088 | not_location.expand_until(between_location); |
| 3089 | not_location |
| 3090 | } else { |
| 3091 | // Consume `BETWEEN` keyword |
| 3092 | *position += 1; |
| 3093 | tokens[*position - 1].location |
| 3094 | }; |
| 3095 | |
| 3096 | let kind = parse_between_expr_kind(tokens, position); |
| 3097 | let range_start = parse_function_call_expression(context, env, tokens, position)?; |
| 3098 | |
| 3099 | // Consume `AND` token |
| 3100 | consume_token_or_error( |
| 3101 | tokens, |
| 3102 | position, |
| 3103 | TokenKind::AndKeyword, |
| 3104 | "Expect `AND` after `BETWEEN` range start", |
| 3105 | )?; |
| 3106 | |
| 3107 | let range_end = parse_function_call_expression(context, env, tokens, position)?; |
| 3108 | |
| 3109 | let lhs_type = expression.expr_type(); |
| 3110 | let range_start_type = &range_start.expr_type(); |
| 3111 | let range_end_type = &range_end.expr_type(); |
| 3112 | |
| 3113 | // Make sure LHS and Range start and end types all are equals |
| 3114 | if !lhs_type.equals(range_start_type) || !lhs_type.equals(range_end_type) { |
| 3115 | return Err(Diagnostic::error(&format!( |
| 3116 | "Expect `BETWEEN` Left hand side type, range start and end to has same type but got {lhs_type}, {} and {}", |
| 3117 | range_start_type.literal(), |
| 3118 | range_end_type.literal() |
| 3119 | )) |
| 3120 | .add_help("Try to make sure all of them has same type") |
| 3121 | .with_location(operator_location) |
| 3122 | .as_boxed()); |
| 3123 | } |
| 3124 |
no test coverage detected
searching dependent graphs…