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

Function parse_node

src/cypher/cypher.c:546–596  ·  view source on GitHub ↗

Parse node: (variable:Label {props}) */

Source from the content-addressed store, hash-verified

544
545/* Parse node: (variable:Label {props}) */
546static int parse_node(parser_t *p, cbm_node_pattern_t *out) {
547 memset(out, 0, sizeof(*out));
548 if (!expect(p, TOK_LPAREN)) {
549 return CBM_NOT_FOUND;
550 }
551
552 /* Optional variable */
553 if (check(p, TOK_IDENT)) {
554 /* Lookahead: if next is COLON, this is a variable */
555 /* Or if next is RPAREN/LBRACE, this is a variable without label */
556 out->variable = heap_strdup(advance(p)->text);
557 }
558
559 /* Optional :Label, with openCypher label alternation :A|B|C (#242).
560 * Stored as a single "A|B|C" string; the matcher splits on '|'. */
561 if (match(p, TOK_COLON)) {
562 const cbm_token_t *label = expect(p, TOK_IDENT);
563 if (!label) {
564 return CBM_NOT_FOUND;
565 }
566 char lbuf[CBM_SZ_256];
567 int ll = snprintf(lbuf, sizeof(lbuf), "%s", label->text);
568 while (match(p, TOK_PIPE)) {
569 const cbm_token_t *alt = expect(p, TOK_IDENT);
570 if (!alt) {
571 return CBM_NOT_FOUND;
572 }
573 int w = snprintf(lbuf + ll, (ll < (int)sizeof(lbuf)) ? sizeof(lbuf) - (size_t)ll : 0,
574 "|%s", alt->text);
575 if (w > 0) {
576 ll += w;
577 }
578 if (ll >= (int)sizeof(lbuf)) {
579 break; /* buffer full */
580 }
581 }
582 out->label = heap_strdup(lbuf);
583 }
584
585 /* Optional {props} */
586 if (check(p, TOK_LBRACE)) {
587 if (parse_props(p, &out->props, &out->prop_count) < 0) {
588 return CBM_NOT_FOUND;
589 }
590 }
591
592 if (!expect(p, TOK_RPAREN)) {
593 return CBM_NOT_FOUND;
594 }
595 return 0;
596}
597
598/* Parse *min..max hop range after the star token has been consumed */
599static void parse_hop_range(parser_t *p, int *min_hops, int *max_hops) {

Callers 2

parse_exists_predicateFunction · 0.85
parse_match_patternFunction · 0.85

Calls 6

expectFunction · 0.85
checkFunction · 0.85
advanceFunction · 0.85
matchFunction · 0.85
parse_propsFunction · 0.85
heap_strdupFunction · 0.70

Tested by

no test coverage detected