diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2020-09-13 16:19:37 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2020-09-13 16:19:37 -0700 |
| commit | ab5ef5a77af9f2fc7c3353f05bf716b1a6b93f73 (patch) | |
| tree | 0df7ca6e1d03e439f085432b1b146ecb9784aab4 | |
| parent | c589b46b4fcc442dc8558b4d62060abb17ec20eb (diff) | |
Added captures in lookaheads/behinds.
| -rw-r--r-- | vm.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -199,21 +199,21 @@ static match_t *_match(grammar_t *g, const char *str, vm_op_t *op, recursive_ref } match_t *before = _match(g, str - backtrack, op->args.pat, rec); if (before == NULL) return NULL; - destroy_match(&before); match_t *m = calloc(sizeof(match_t), 1); m->start = str; m->end = str; m->op = op; + m->child = before; return m; } case VM_BEFORE: { match_t *after = _match(g, str, op->args.pat, rec); if (after == NULL) return NULL; - destroy_match(&after); match_t *m = calloc(sizeof(match_t), 1); m->start = str; m->end = str; m->op = op; + m->child = after; return m; } case VM_CAPTURE: { @@ -511,6 +511,10 @@ void print_match(match_t *m, const char *color, int verbose) // printf("\033[0;2;33m[%s:", name); const char *prev = m->start; for (match_t *child = m->child; child; child = child->nextsibling) { + // Skip children from e.g. zero-width matches like >@foo + if (!(m->start <= child->start && child->start <= m->end && + m->start <= child->end && child->end <= m->end)) + continue; if (child->start > prev) printf("%s%.*s", color ? color : "", (int)(child->start - prev), prev); print_match(child, color ? (m->is_capture ? "\033[0;31;1m" : color) : NULL, verbose); |
