MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / parse_query_block

Function parse_query_block

src/cypher/cypher.c:2051–2113  ·  view source on GitHub ↗

One MATCH ... RETURN block: the whole query, or one branch of a UNION. On * failure p->error holds the message and *out stays NULL. */

Source from the content-addressed store, hash-verified

2049/* One MATCH ... RETURN block: the whole query, or one branch of a UNION. On
2050 * failure p->error holds the message and *out stays NULL. */
2051static int parse_query_block(parser_t *p, cbm_query_t **out) {
2052 *out = NULL;
2053 /* Each block starts with a clean message, as it did when every UNION
2054 * branch had a parser of its own. */
2055 p->error[0] = '\0';
2056
2057 /* Check for unsupported leading keywords */
2058 const char *unsup = unsupported_clause_error(peek(p)->type);
2059 if (unsup) {
2060 snprintf(p->error, sizeof(p->error), "%s", unsup);
2061 return CBM_NOT_FOUND;
2062 }
2063
2064 cbm_query_t *q = calloc(CBM_ALLOC_ONE, sizeof(cbm_query_t));
2065
2066 if (check(p, TOK_UNWIND)) {
2067 parse_unwind_clause(p, q);
2068 }
2069
2070 bool first_optional = false;
2071 if (check(p, TOK_OPTIONAL)) {
2072 advance(p);
2073 first_optional = true;
2074 }
2075 if (!expect(p, TOK_MATCH)) {
2076 parse_error_default(p, "expected MATCH");
2077 cbm_query_free(q);
2078 return CBM_NOT_FOUND;
2079 }
2080
2081 int pat_cap = CYP_INIT_CAP4;
2082 q->patterns = malloc(pat_cap * sizeof(cbm_pattern_t));
2083 q->pattern_optional = malloc(pat_cap * sizeof(bool));
2084
2085 if (parse_match_pattern(p, &q->patterns[0]) < 0) {
2086 parse_error_default(p, "failed to parse pattern");
2087 cbm_query_free(q);
2088 return CBM_NOT_FOUND;
2089 }
2090 q->pattern_optional[0] = first_optional;
2091 q->pattern_count = SKIP_ONE;
2092
2093 if (parse_match_chain(p, q, &pat_cap) < 0) {
2094 parse_error_default(p, "failed to parse additional pattern");
2095 cbm_query_free(q);
2096 return CBM_NOT_FOUND;
2097 }
2098
2099 if (parse_where(p, &q->where) < 0) {
2100 parse_error_default(p, "failed to parse WHERE");
2101 cbm_query_free(q);
2102 return CBM_NOT_FOUND;
2103 }
2104
2105 if (parse_post_where(p, q, &pat_cap) < 0) {
2106 parse_error_default(p, "failed to parse query");
2107 cbm_query_free(q);
2108 return CBM_NOT_FOUND;

Callers 1

cbm_parseFunction · 0.85

Calls 12

unsupported_clause_errorFunction · 0.85
peekFunction · 0.85
parse_unwind_clauseFunction · 0.85
expectFunction · 0.85
parse_error_defaultFunction · 0.85
cbm_query_freeFunction · 0.85
parse_match_patternFunction · 0.85
parse_match_chainFunction · 0.85
parse_whereFunction · 0.85
parse_post_whereFunction · 0.85
checkFunction · 0.70
advanceFunction · 0.70

Tested by

no test coverage detected