From 9ae083d81642be3a3ee7ff1e8d28fb9381bb1abf Mon Sep 17 00:00:00 2001 From: spew Date: Thu, 2 Feb 2017 21:21:34 -0600 Subject: libregexp: simplify regular expression vm implementation Make the logic around who has priority over the final match simpler by merging the priority generation and match fields in a smarter way. Move the creation of new thread matches up to the top to avoid jumping all over the place. --- sys/src/libregexp/regcomp.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'sys/src/libregexp/regcomp.c') diff --git a/sys/src/libregexp/regcomp.c b/sys/src/libregexp/regcomp.c index ad3b8cd96..3e3ba6ae5 100644 --- a/sys/src/libregexp/regcomp.c +++ b/sys/src/libregexp/regcomp.c @@ -156,17 +156,6 @@ initplex(Parselex *plex, char *regstr, int lit) return plex; } -static int -maxthreads(Renode *tree) -{ - tree = tree->left; - if(tree->op == TCAT) - tree = tree->left; - if(tree->op == TBOL) - return 2; - return -1; -} - static Reprog* regcomp1(char *regstr, int nl, int lit) { @@ -187,7 +176,7 @@ regcomp1(char *regstr, int nl, int lit) return nil; } - maxthr = regstrlen; + maxthr = regstrlen + 1; parsetr = node(&plex, TSUB, e0(&plex), nil); // prtree(parsetr, 0, 1); @@ -304,12 +293,13 @@ Tailcall: static Reinst* compile(Renode *parsetr, Reprog *reprog, int nl) { - Reinst *reinst; + Reinst *reinst, *end; int sub; sub = 0; reinst = (Reinst*)(reprog+1); - compile1(parsetr, reinst, &sub, nl); + end = compile1(parsetr, reinst, &sub, nl); + assert(reinst + reprog->len == end); return reinst; } -- cgit v1.2.3