From cbe1d97b37963a7ab75900463570cb6a109be8b4 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 15 Jan 2021 12:12:56 -0800 Subject: Fixed bug with backrefs. The backref pushing was overly greedy and has been updated to only push backrefs when a capture is directly in the chain and not recursively contained within it. --- grammar.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) (limited to 'grammar.c') diff --git a/grammar.c b/grammar.c index 3b3d349..1c9c3b6 100644 --- a/grammar.c +++ b/grammar.c @@ -10,9 +10,6 @@ #include "grammar.h" #include "utils.h" -__attribute__((nonnull(2,3,4), returns_nonnull)) -static def_t *with_backref(def_t *defs, file_t *f, const char *name, match_t *m); - // // Return a new list of definitions with one added to the front // @@ -71,7 +68,7 @@ def_t *lookup(def_t *defs, const char *name) // // Push a backreference onto the backreference stack // -static def_t *with_backref(def_t *defs, file_t *f, const char *name, match_t *m) +def_t *with_backref(def_t *defs, file_t *f, const char *name, match_t *m) { vm_op_t *op = new_op(f, m->start, VM_BACKREF); op->end = m->end; @@ -80,20 +77,6 @@ static def_t *with_backref(def_t *defs, file_t *f, const char *name, match_t *m) return with_def(defs, f, strlen(name), name, op); } -// -// Push all the backreferences contained in a match onto the backreference stack -// -def_t *with_backrefs(def_t *defs, file_t *f, match_t *m) -{ - if (m->op->type != VM_REF) { - if (m->op->type == VM_CAPTURE && m->op->args.capture.name) - defs = with_backref(defs, f, m->op->args.capture.name, m->child); - if (m->child) defs = with_backrefs(defs, f, m->child); - if (m->nextsibling) defs = with_backrefs(defs, f, m->nextsibling); - } - return defs; -} - // // Free all the given definitions up till (but not including) `stop` // -- cgit v1.2.3