MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / try_parse

Function try_parse

nodedb-sql/src/ddl_ast/graph_parse/mod.rs:35–80  ·  view source on GitHub ↗

Entry point: returns `Some` when `sql` starts with a graph DSL keyword (`GRAPH ...`, `MATCH ...`, `OPTIONAL MATCH ...`), else `None` so the main DDL parser can continue trying other cases.

(sql: &str)

Source from the content-addressed store, hash-verified

33/// keyword (`GRAPH ...`, `MATCH ...`, `OPTIONAL MATCH ...`), else
34/// `None` so the main DDL parser can continue trying other cases.
35pub fn try_parse(sql: &str) -> Option<NodedbStatement> {
36 let trimmed = sql.trim();
37 let upper = trimmed.to_ascii_uppercase();
38
39 if upper.starts_with("MATCH ") || upper.starts_with("OPTIONAL MATCH ") {
40 return Some(NodedbStatement::Graph(GraphStmt::MatchQuery {
41 body: trimmed.to_string(),
42 }));
43 }
44
45 if !upper.starts_with("GRAPH ") {
46 return None;
47 }
48
49 let toks = tokenizer::tokenize(trimmed);
50
51 if upper.starts_with("GRAPH INSERT EDGE ") {
52 return variants::parse_insert_edge(&toks);
53 }
54 if upper.starts_with("GRAPH DELETE EDGE ") {
55 return variants::parse_delete_edge(&toks);
56 }
57 if upper.starts_with("GRAPH LABEL ") {
58 return variants::parse_set_labels(&toks, false);
59 }
60 if upper.starts_with("GRAPH UNLABEL ") {
61 return variants::parse_set_labels(&toks, true);
62 }
63 if upper.starts_with("GRAPH TRAVERSE ") {
64 return variants::parse_traverse(&toks);
65 }
66 if upper.starts_with("GRAPH NEIGHBORS ") {
67 return variants::parse_neighbors(&toks);
68 }
69 if upper.starts_with("GRAPH PATH ") {
70 return variants::parse_path(&toks);
71 }
72 if upper.starts_with("GRAPH ALGO ") {
73 return variants::parse_algo(&toks);
74 }
75 if upper.starts_with("GRAPH RAG FUSION ") {
76 return variants::parse_rag_fusion(&toks, trimmed);
77 }
78
79 None
80}
81
82#[cfg(test)]
83mod tests {

Calls 10

parse_insert_edgeFunction · 0.85
parse_delete_edgeFunction · 0.85
parse_set_labelsFunction · 0.85
parse_traverseFunction · 0.85
parse_neighborsFunction · 0.85
parse_pathFunction · 0.85
parse_algoFunction · 0.85
parse_rag_fusionFunction · 0.85
to_stringMethod · 0.80
tokenizeFunction · 0.70