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