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

Function parse_condition_op

src/cypher/cypher.c:1077–1131  ·  view source on GitHub ↗

Parse the operator + value tail shared by every condition subject * (var[.prop] and multi-arg functions like coalesce(...)): IS [NOT] NULL, * IN [...], or a comparison operator with a literal value. */

Source from the content-addressed store, hash-verified

1075 * (var[.prop] and multi-arg functions like coalesce(...)): IS [NOT] NULL,
1076 * IN [...], or a comparison operator with a literal value. */
1077static cbm_expr_t *parse_condition_op(parser_t *p, cbm_condition_t *c) {
1078 /* IS NULL / IS NOT NULL */
1079 if (check(p, TOK_IS)) {
1080 advance(p);
1081 if (match(p, TOK_NOT)) {
1082 c->op = heap_strdup("IS NOT NULL");
1083 expect(p, TOK_NULL_KW);
1084 } else {
1085 expect(p, TOK_NULL_KW);
1086 c->op = heap_strdup("IS NULL");
1087 }
1088 return expr_leaf(*c);
1089 }
1090
1091 /* IN [...] */
1092 if (check(p, TOK_IN)) {
1093 cbm_expr_t *e = parse_in_list(p, c);
1094 if (!e) {
1095 cond_func_fields_free(c);
1096 }
1097 return e;
1098 }
1099
1100 /* Standard operators */
1101 c->op = parse_comparison_op(p);
1102 if (!c->op) {
1103 snprintf(p->error, sizeof(p->error), "unexpected operator at pos %d", peek(p)->pos);
1104 cond_func_fields_free(c);
1105 safe_str_free(&c->variable);
1106 safe_str_free(&c->property);
1107 safe_str_free(&c->coalesce_default);
1108 return NULL;
1109 }
1110
1111 /* Value */
1112 if (check(p, TOK_STRING) || check(p, TOK_NUMBER)) {
1113 c->value = heap_strdup(advance(p)->text);
1114 } else if (check(p, TOK_TRUE)) {
1115 advance(p);
1116 c->value = heap_strdup("true");
1117 } else if (check(p, TOK_FALSE)) {
1118 advance(p);
1119 c->value = heap_strdup("false");
1120 } else {
1121 snprintf(p->error, sizeof(p->error), "expected value at pos %d", peek(p)->pos);
1122 cond_func_fields_free(c);
1123 safe_str_free(&c->variable);
1124 safe_str_free(&c->property);
1125 safe_str_free(&c->op);
1126 safe_str_free(&c->coalesce_default);
1127 return NULL;
1128 }
1129
1130 return expr_leaf(*c);
1131}
1132
1133/* parse_condition_lhs result: the label-test form is a complete condition. */
1134enum { COND_LHS_COMPLETE = 1 };

Callers 1

parse_condition_exprFunction · 0.85

Calls 11

advanceFunction · 0.85
matchFunction · 0.85
expectFunction · 0.85
expr_leafFunction · 0.85
parse_in_listFunction · 0.85
cond_func_fields_freeFunction · 0.85
parse_comparison_opFunction · 0.85
peekFunction · 0.85
safe_str_freeFunction · 0.85
checkFunction · 0.70
heap_strdupFunction · 0.70

Tested by

no test coverage detected