From e071ac7b12260b4dcbc80f4c864706de29a6d3c9 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 2 May 2022 17:23:02 -0400 Subject: Bugfix for left recursion --- match.c | 2 ++ tests/29-left-recursion3.in | 1 + tests/29-left-recursion3.out | 1 + tests/29-left-recursion3.sh | 2 ++ 4 files changed, 6 insertions(+) create mode 100644 tests/29-left-recursion3.in create mode 100644 tests/29-left-recursion3.out create mode 100644 tests/29-left-recursion3.sh diff --git a/match.c b/match.c index 2252fc3..8231fc0 100644 --- a/match.c +++ b/match.c @@ -667,7 +667,9 @@ static match_t *match(match_ctx_t *ctx, const char *str, pat_t *pat) while (1) { const char *prev = m->end; rec_op.args.leftrec.match = m; + ctx2.cache = &(cache_t){0}; match_t *m2 = match(&ctx2, str, ref); + cache_destroy(&ctx2); if (!m2) break; if (m2->end <= prev) { recycle_match(&m2); diff --git a/tests/29-left-recursion3.in b/tests/29-left-recursion3.in new file mode 100644 index 0000000..0830ff2 --- /dev/null +++ b/tests/29-left-recursion3.in @@ -0,0 +1 @@ +f!!! diff --git a/tests/29-left-recursion3.out b/tests/29-left-recursion3.out new file mode 100644 index 0000000..8ca1cbc --- /dev/null +++ b/tests/29-left-recursion3.out @@ -0,0 +1 @@ +{f!!!} diff --git a/tests/29-left-recursion3.sh b/tests/29-left-recursion3.sh new file mode 100644 index 0000000..7de7379 --- /dev/null +++ b/tests/29-left-recursion3.sh @@ -0,0 +1,2 @@ +# Left recursion has some tricky edge cases like this: +bp -p 'shout: phrase `!; phrase: shout / id; phrase => "{@0}"' -- cgit v1.2.3