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

Function parse_from_option

crates/gitql-parser/src/parser.rs:831–983  ·  view source on GitHub ↗
(
    context: &mut ParserContext,
    env: &mut Environment,
    tables_to_select_from: &mut Vec<String>,
    joins: &mut Vec<Join>,
    tokens: &[Token],
    position: &mut usize,
)

Source from the content-addressed store, hash-verified

829}
830
831fn parse_from_option(
832 context: &mut ParserContext,
833 env: &mut Environment,
834 tables_to_select_from: &mut Vec<String>,
835 joins: &mut Vec<Join>,
836 tokens: &[Token],
837 position: &mut usize,
838) -> Result<(), Box<Diagnostic>> {
839 if is_current_token(tokens, position, TokenKind::From) {
840 // Consume `From` keyword
841 *position += 1;
842
843 // Parse and consume Symbol as Table name
844 let table_name = consume_conditional_token_or_errors(
845 tokens,
846 position,
847 |token| matches!(token.kind, TokenKind::Symbol(_)),
848 "Expect `Table` value after `FROM` keyword",
849 )?
850 .to_string();
851
852 if !env
853 .schema
854 .tables_fields_names
855 .contains_key(table_name.as_str())
856 {
857 let mut diagnostic =
858 Diagnostic::error(&format!("Cannot find table with name `{table_name}`"))
859 .add_note("You can use the `SHOW TABLES` query to get list of current tables")
860 .add_note("Check the documentations to see available tables")
861 .with_location(calculate_safe_location(tokens, *position));
862
863 let canditates: Vec<&&str> = env.schema.tables_fields_names.keys().collect();
864 if let Some(closest_valid_name) = find_closeest_string(&table_name, &canditates) {
865 let message =
866 &format!("a table with a similar name exists: `{closest_valid_name}`");
867 diagnostic = diagnostic.add_help(message);
868 }
869
870 return Err(diagnostic.as_boxed());
871 }
872
873 // Register the table
874 tables_to_select_from.push(table_name.to_string());
875 context.selected_tables.push(table_name.to_string());
876 register_current_table_fields_types(env, &table_name)?;
877
878 // Parse Joins
879 let mut number_previous_of_joins = 0;
880 while is_join_or_join_type_token(tokens, position) {
881 let join_token = &tokens[*position];
882
883 // The default join type now is cross join because we don't support `ON` Condition
884 let mut join_kind = JoinKind::Default;
885 if join_token.kind != TokenKind::Join {
886 join_kind = match join_token.kind {
887 TokenKind::Left => JoinKind::Left,
888 TokenKind::Right => JoinKind::Right,

Callers 1

parse_select_statementFunction · 0.85

Calls 13

is_current_tokenFunction · 0.85
calculate_safe_locationFunction · 0.85
find_closeest_stringFunction · 0.85
parse_expressionFunction · 0.85
with_locationMethod · 0.80
add_noteMethod · 0.80
add_helpMethod · 0.80
as_boxedMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…