Parse relationship: -[:TYPE|TYPE2*min..max]-> or <-[...]- */
| 738 | |
| 739 | /* Parse relationship: -[:TYPE|TYPE2*min..max]-> or <-[...]- */ |
| 740 | static int parse_rel(parser_t *p, cbm_rel_pattern_t *out) { |
| 741 | memset(out, 0, sizeof(*out)); |
| 742 | out->min_hops = SKIP_ONE; |
| 743 | out->max_hops = SKIP_ONE; |
| 744 | |
| 745 | /* Check for leading < (inbound) */ |
| 746 | bool leading_lt = match(p, TOK_LT); |
| 747 | if (!expect(p, TOK_DASH)) { |
| 748 | return CBM_NOT_FOUND; |
| 749 | } |
| 750 | |
| 751 | /* Optional bracket content */ |
| 752 | if (match(p, TOK_LBRACKET)) { |
| 753 | if (parse_rel_bracket(p, out) < 0) { |
| 754 | return CBM_NOT_FOUND; |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | if (!expect(p, TOK_DASH)) { |
| 759 | return CBM_NOT_FOUND; |
| 760 | } |
| 761 | |
| 762 | /* Check for trailing > (outbound) */ |
| 763 | bool trailing_gt = match(p, TOK_GT); |
| 764 | |
| 765 | /* Determine direction */ |
| 766 | if (leading_lt && !trailing_gt) { |
| 767 | out->direction = heap_strdup("inbound"); |
| 768 | } else if (!leading_lt && trailing_gt) { |
| 769 | out->direction = heap_strdup("outbound"); |
| 770 | } else { |
| 771 | out->direction = heap_strdup("any"); |
| 772 | } |
| 773 | |
| 774 | return 0; |
| 775 | } |
| 776 | |
| 777 | /* ── Expression tree helpers ────────────────────────────────────── */ |
| 778 |
no test coverage detected