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

Function parse_between_expression

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

Source from the content-addressed store, hash-verified

3065}
3066
3067fn 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

Callers 1

Calls 15

is_current_tokenFunction · 0.85
is_next_tokenFunction · 0.85
parse_between_expr_kindFunction · 0.85
consume_token_or_errorFunction · 0.85
expand_untilMethod · 0.80
expr_typeMethod · 0.80
as_boxedMethod · 0.80
with_locationMethod · 0.80
add_helpMethod · 0.80
containsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…