Parse node: (variable:Label {props}) */
| 570 | |
| 571 | /* Parse node: (variable:Label {props}) */ |
| 572 | static int parse_node(parser_t *p, cbm_node_pattern_t *out) { |
| 573 | memset(out, 0, sizeof(*out)); |
| 574 | if (!expect(p, TOK_LPAREN)) { |
| 575 | return CBM_NOT_FOUND; |
| 576 | } |
| 577 | |
| 578 | /* Optional variable */ |
| 579 | if (check(p, TOK_IDENT)) { |
| 580 | /* Lookahead: if next is COLON, this is a variable */ |
| 581 | /* Or if next is RPAREN/LBRACE, this is a variable without label */ |
| 582 | out->variable = heap_strdup(advance(p)->text); |
| 583 | } |
| 584 | |
| 585 | /* Optional :Label, with openCypher label alternation :A|B|C (#242). |
| 586 | * Stored as a single "A|B|C" string; the matcher splits on '|'. */ |
| 587 | if (match(p, TOK_COLON)) { |
| 588 | const cbm_token_t *label = expect(p, TOK_IDENT); |
| 589 | if (!label) { |
| 590 | return CBM_NOT_FOUND; |
| 591 | } |
| 592 | char lbuf[CBM_SZ_256]; |
| 593 | int ll = snprintf(lbuf, sizeof(lbuf), "%s", label->text); |
| 594 | while (match(p, TOK_PIPE)) { |
| 595 | const cbm_token_t *alt = expect(p, TOK_IDENT); |
| 596 | if (!alt) { |
| 597 | return CBM_NOT_FOUND; |
| 598 | } |
| 599 | int w = snprintf(lbuf + ll, (ll < (int)sizeof(lbuf)) ? sizeof(lbuf) - (size_t)ll : 0, |
| 600 | "|%s", alt->text); |
| 601 | if (w > 0) { |
| 602 | ll += w; |
| 603 | } |
| 604 | if (ll >= (int)sizeof(lbuf)) { |
| 605 | break; /* buffer full */ |
| 606 | } |
| 607 | } |
| 608 | out->label = heap_strdup(lbuf); |
| 609 | } |
| 610 | |
| 611 | /* Optional {props} */ |
| 612 | if (check(p, TOK_LBRACE)) { |
| 613 | if (parse_props(p, &out->props, &out->prop_count) < 0) { |
| 614 | return CBM_NOT_FOUND; |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | if (!expect(p, TOK_RPAREN)) { |
| 619 | return CBM_NOT_FOUND; |
| 620 | } |
| 621 | return 0; |
| 622 | } |
| 623 | |
| 624 | /* Parse *min..max hop range after the star token has been consumed */ |
| 625 | static void parse_hop_range(parser_t *p, int *min_hops, int *max_hops) { |
no test coverage detected