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

Function parse_props

src/cypher/cypher.c:518–578  ·  view source on GitHub ↗

Parse inline properties: {key: "value", ...} */

Source from the content-addressed store, hash-verified

516
517/* Parse inline properties: {key: "value", ...} */
518static int parse_props(parser_t *p, cbm_prop_filter_t **out, int *count) {
519 *out = NULL;
520 *count = 0;
521 if (!match(p, TOK_LBRACE)) {
522 return 0;
523 }
524
525 int cap = CYP_INIT_CAP4;
526 int n = 0;
527 cbm_prop_filter_t *arr = malloc(cap * sizeof(cbm_prop_filter_t));
528 if (!arr) {
529 return CBM_NOT_FOUND;
530 }
531
532 while (!check(p, TOK_RBRACE) && !check(p, TOK_EOF)) {
533 /* Every failure frees the entries already parsed, not only the array. */
534 const cbm_token_t *key = expect(p, TOK_IDENT);
535 if (!key) {
536 free_prop_entries(arr, n);
537 return CBM_NOT_FOUND;
538 }
539 if (!expect(p, TOK_COLON)) {
540 free_prop_entries(arr, n);
541 return CBM_NOT_FOUND;
542 }
543 const cbm_token_t *val = expect(p, TOK_STRING);
544 if (!val) {
545 free_prop_entries(arr, n);
546 return CBM_NOT_FOUND;
547 }
548
549 if (n >= cap) {
550 int new_cap = cap * PAIR_LEN;
551 void *tmp = realloc(arr, new_cap * sizeof(cbm_prop_filter_t));
552 if (!tmp) {
553 free_prop_entries(arr, n);
554 return CBM_NOT_FOUND;
555 }
556 arr = tmp;
557 cap = new_cap;
558 }
559 const char *new_key = heap_strdup(key->text);
560 const char *new_val = heap_strdup(val->text);
561 if (!new_key || !new_val) {
562 safe_str_free(&new_key);
563 safe_str_free(&new_val);
564 free_prop_entries(arr, n);
565 return CBM_NOT_FOUND;
566 }
567 arr[n].key = new_key;
568 arr[n].value = new_val;
569 n++;
570
571 match(p, TOK_COMMA); /* optional comma */
572 }
573 expect(p, TOK_RBRACE);
574
575 *out = arr;

Callers 1

parse_nodeFunction · 0.85

Calls 6

matchFunction · 0.85
expectFunction · 0.85
free_prop_entriesFunction · 0.85
safe_str_freeFunction · 0.85
checkFunction · 0.70
heap_strdupFunction · 0.70

Tested by

no test coverage detected