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

Function parse_set_query

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

Source from the content-addressed store, hash-verified

119}
120
121fn parse_set_query(
122 env: &mut Environment,
123 tokens: &[Token],
124 position: &mut usize,
125) -> Result<Query, Box<Diagnostic>> {
126 let len = tokens.len();
127 let mut context = ParserContext::default();
128
129 // Consume Set keyword
130 *position += 1;
131
132 if !is_current_token_with_condition(tokens, position, |token| {
133 matches!(token.kind, TokenKind::GlobalVariable(_))
134 }) {
135 return Err(Diagnostic::error(
136 "Expect Global variable name start with `@` after `SET` keyword",
137 )
138 .with_location(calculate_safe_location(tokens, *position - 1))
139 .as_boxed());
140 }
141
142 let name = &tokens[*position].to_string();
143
144 // Consume variable name
145 *position += 1;
146
147 if *position >= len || !is_assignment_operator(&tokens[*position]) {
148 return Err(
149 Diagnostic::error("Expect `=` or `:=` and Value after Variable name")
150 .with_location(calculate_safe_location(tokens, *position - 1))
151 .as_boxed(),
152 );
153 }
154
155 // Consume `=` or `:=` token
156 *position += 1;
157
158 let aggregations_count_before = context.aggregations.len();
159 let value = parse_expression(&mut context, env, tokens, position)?;
160 let has_aggregations = context.aggregations.len() != aggregations_count_before;
161
162 // Until supports sub queries, aggregation value can't be stored in variables
163 if has_aggregations {
164 return Err(
165 Diagnostic::error("Aggregation value can't be assigned to global variable")
166 .with_location(calculate_safe_location(tokens, *position - 1))
167 .as_boxed(),
168 );
169 }
170
171 env.define_global(name.to_string(), value.expr_type());
172
173 Ok(Query::GlobalVariableDecl(GlobalVariableDeclQuery {
174 name: name.to_string(),
175 value,
176 }))
177}
178

Callers 1

parse_gqlFunction · 0.85

Calls 9

calculate_safe_locationFunction · 0.85
is_assignment_operatorFunction · 0.85
parse_expressionFunction · 0.85
as_boxedMethod · 0.80
with_locationMethod · 0.80
define_globalMethod · 0.80
expr_typeMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…