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

Function parse_select_query

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

Source from the content-addressed store, hash-verified

238}
239
240fn parse_select_query(
241 env: &mut Environment,
242 tokens: &[Token],
243 position: &mut usize,
244) -> Result<Query, Box<Diagnostic>> {
245 let len = tokens.len();
246
247 let mut context = ParserContext::default();
248 let mut statements: HashMap<&'static str, Statement> = HashMap::new();
249
250 while *position < len {
251 let token = &tokens[*position];
252
253 match &token.kind {
254 TokenKind::Select => {
255 if statements.contains_key("select") {
256 return Err(Diagnostic::error("You already used `SELECT` statement")
257 .add_note("Can't use more than one `SELECT` statement in the same query")
258 .add_help("If you have more than one query, end each one with `;`")
259 .with_location(token.location)
260 .as_boxed());
261 }
262 let statement = parse_select_statement(&mut context, env, tokens, position)?;
263 statements.insert("select", statement);
264 context.is_single_value_query = !context.aggregations.is_empty();
265 context.has_select_statement = true;
266 }
267 TokenKind::Where => {
268 if statements.contains_key("where") {
269 return Err(Diagnostic::error("You already used `WHERE` statement")
270 .add_note("Can't use more than one `WHERE` statement in the same query")
271 .with_location(token.location)
272 .as_boxed());
273 }
274
275 let statement = parse_where_statement(&mut context, env, tokens, position)?;
276 statements.insert("where", statement);
277 }
278 TokenKind::Qualify => {
279 if statements.contains_key("qualify") {
280 return Err(Diagnostic::error("You already used `QUALIFY` statement")
281 .add_note("Can't use more than one `QUALIFY` statement in the same query")
282 .with_location(token.location)
283 .as_boxed());
284 }
285 let statement = parse_qualify_statement(&mut context, env, tokens, position)?;
286 statements.insert("qualify", statement);
287 }
288 TokenKind::Group => {
289 if statements.contains_key("group") {
290 return Err(Diagnostic::error("`You already used `GROUP BY` statement")
291 .add_note("Can't use more than one `GROUP BY` statement in the same query")
292 .with_location(token.location)
293 .as_boxed());
294 }
295
296 let statement = parse_group_by_statement(&mut context, env, tokens, position)?;
297 statements.insert("group", statement);

Callers 1

parse_gqlFunction · 0.85

Calls 15

parse_select_statementFunction · 0.85
parse_where_statementFunction · 0.85
parse_qualify_statementFunction · 0.85
parse_group_by_statementFunction · 0.85
parse_having_statementFunction · 0.85
parse_limit_statementFunction · 0.85
is_current_tokenFunction · 0.85
calculate_safe_locationFunction · 0.85
parse_offset_statementFunction · 0.85
parse_order_by_statementFunction · 0.85
parse_into_statementFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…