From 4649efb0b4eeb1515bc92711ecb65a2bce23d202 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 27 Jun 2021 12:06:26 -0700 Subject: regex-from-trie: bugs processing compressed trie. * filter.c (regex_from_trie): If a hash key maps to a string, do not treat that as a trie; it is the value for that node. A value is only a trie if it is a cons or hash. Also, in this case do not make a compound regex. * tests/015/trie.tl: Add duplicate of regex test case using regex from compressed tree. --- filter.c | 8 +++++--- tests/015/trie.tl | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/filter.c b/filter.c index 2993f82d..a8f0b787 100644 --- a/filter.c +++ b/filter.c @@ -154,10 +154,12 @@ static val regex_from_trie(val trie) us_hash_iter_init(&hi, trie); while ((cell = hash_iter_next(&hi)) != nil) { - val rx = regex_from_trie(us_cdr(cell)); + val a = us_car(cell); + val d = us_cdr(cell); + val rx = if2(consp(d) || hashp(d), regex_from_trie(d)); val ry = if3(consp(rx) && car(rx) == compound_s, - cons(compound_s, cons(us_car(cell), cdr(rx))), - list(compound_s, us_car(cell), rx, nao)); + cons(compound_s, cons(a, cdr(rx))), + if3(rx, list(compound_s, a, rx, nao), a)); if (out) out = list(or_s, ry, out, nao); else diff --git a/tests/015/trie.tl b/tests/015/trie.tl index 48e7e050..de88a797 100644 --- a/tests/015/trie.tl +++ b/tests/015/trie.tl @@ -33,6 +33,7 @@ (trie-compress tr1) (defvarl rx0 (regex-compile (regex-from-trie tr0))) +(defvarl rx1 (regex-compile (regex-from-trie tr1))) (mvtest (build (each ((d dat)) (add (filter-string-tree tr0 d)))) enu @@ -47,3 +48,7 @@ (mvtest (build (each ((d dat)) (add [rx0 d]))) dat (build (each ((n ndt)) (add [rx0 n]))) (repeat '(nil) (len dat))) + +(mvtest + (build (each ((d dat)) (add [rx1 d]))) dat + (build (each ((n ndt)) (add [rx1 n]))) (repeat '(nil) (len dat))) -- cgit v1.2.3