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

Function parse_condition_lhs

src/cypher/cypher.c:1139–1200  ·  view source on GitHub ↗

Parse the left-hand side of a WHERE condition into c. * Returns CBM_NOT_FOUND on error, 0 when an operator/value should follow, and * COND_LHS_COMPLETE when the condition is already complete (label test). */

Source from the content-addressed store, hash-verified

1137 * Returns CBM_NOT_FOUND on error, 0 when an operator/value should follow, and
1138 * COND_LHS_COMPLETE when the condition is already complete (label test). */
1139static int parse_condition_lhs(parser_t *p, cbm_condition_t *c) {
1140 if (is_multiarg_func_call(p)) {
1141 /* Multi-arg scalar function LHS: coalesce(f.depth, 0) >= 2 (#874).
1142 * Reuse the RETURN-item parser, then move ownership into the condition. */
1143 cbm_return_item_t fitem;
1144 memset(&fitem, 0, sizeof(fitem));
1145 if (parse_multiarg_func_item(p, &fitem) < 0) {
1146 func_item_fields_free(&fitem);
1147 return CBM_NOT_FOUND;
1148 }
1149 c->variable = fitem.variable;
1150 c->property = fitem.property;
1151 c->func = fitem.func;
1152 c->args = fitem.args;
1153 c->arg_count = fitem.arg_count;
1154 return 0;
1155 }
1156
1157 if (check(p, TOK_IDENT) && p->pos + SKIP_ONE < p->count &&
1158 p->tokens[p->pos + SKIP_ONE].type == TOK_LPAREN) {
1159 /* Unrecognised function call in WHERE — fail loudly with the supported
1160 * set instead of the misleading "unexpected operator" (#874). */
1161 snprintf(p->error, sizeof(p->error),
1162 "unsupported function '%s' in WHERE (supported: coalesce, substring, replace, "
1163 "left, right)",
1164 peek(p)->text);
1165 return CBM_NOT_FOUND;
1166 }
1167
1168 const cbm_token_t *var = expect(p, TOK_IDENT);
1169 if (!var) {
1170 return CBM_NOT_FOUND;
1171 }
1172
1173 /* Label test: WHERE n:Label (openCypher, #241). Modelled as a leaf with
1174 * op="HAS_LABEL" and value=Label, evaluated against the bound node's label. */
1175 if (check(p, TOK_COLON)) {
1176 advance(p);
1177 const cbm_token_t *lbl = expect(p, TOK_IDENT);
1178 if (!lbl) {
1179 return CBM_NOT_FOUND;
1180 }
1181 c->variable = heap_strdup(var->text);
1182 c->op = heap_strdup("HAS_LABEL");
1183 c->value = heap_strdup(lbl->text);
1184 return COND_LHS_COMPLETE;
1185 }
1186
1187 if (match(p, TOK_DOT)) {
1188 const cbm_token_t *prop = expect(p, TOK_IDENT);
1189 if (!prop) {
1190 return CBM_NOT_FOUND;
1191 }
1192 c->variable = heap_strdup(var->text);
1193 c->property = heap_strdup(prop->text);
1194 } else {
1195 /* No dot: bare alias (e.g. post-WITH variable like "cnt") */
1196 c->variable = heap_strdup(var->text);

Callers 1

parse_condition_exprFunction · 0.85

Calls 9

is_multiarg_func_callFunction · 0.85
parse_multiarg_func_itemFunction · 0.85
func_item_fields_freeFunction · 0.85
peekFunction · 0.85
expectFunction · 0.85
advanceFunction · 0.85
matchFunction · 0.85
checkFunction · 0.70
heap_strdupFunction · 0.70

Tested by

no test coverage detected