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

Function parse_describe_query

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

Source from the content-addressed store, hash-verified

177}
178
179fn parse_describe_query(
180 env: &mut Environment,
181 tokens: &[Token],
182 position: &mut usize,
183) -> Result<Query, Box<Diagnostic>> {
184 // Consume `DESCRIBE` keyword
185 *position += 1;
186
187 if *position >= tokens.len() || !matches!(tokens[*position].kind, TokenKind::Symbol(_)) {
188 return Err(
189 Diagnostic::error("Expect table name after DESCRIBE Statement")
190 .with_location(calculate_safe_location(tokens, *position))
191 .as_boxed(),
192 );
193 }
194
195 // Make sure table name is valid
196 let table_name = tokens[*position].to_string();
197 if !env
198 .schema
199 .tables_fields_names
200 .contains_key(table_name.as_str())
201 {
202 let mut diagnostic =
203 Diagnostic::error(&format!("Cannot find table with name `{table_name}`"))
204 .add_note("You can use the `SHOW TABLES` query to get list of current tables")
205 .add_note("Check the documentations to see available tables")
206 .with_location(calculate_safe_location(tokens, *position));
207
208 let canditates: Vec<&&str> = env.schema.tables_fields_names.keys().collect();
209 if let Some(closest_valid_name) = find_closeest_string(&table_name, &canditates) {
210 let message = &format!("a table with a similar name exists: `{closest_valid_name}`");
211 diagnostic = diagnostic.add_help(message);
212 }
213
214 return Err(diagnostic.as_boxed());
215 }
216
217 // Consume Table Name
218 *position += 1;
219
220 Ok(Query::DescribeTable(DescribeQuery { table_name }))
221}
222
223fn parse_show_query(tokens: &[Token], position: &mut usize) -> Result<Query, Box<Diagnostic>> {
224 // Consume SHOW keyword

Callers 1

parse_gqlFunction · 0.85

Calls 7

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…