summaryrefslogtreecommitdiff
path: root/sys/src/libregexp/regcomp.c
diff options
context:
space:
mode:
authorspew <devnull@localhost>2017-02-02 21:21:34 -0600
committerspew <devnull@localhost>2017-02-02 21:21:34 -0600
commit9ae083d81642be3a3ee7ff1e8d28fb9381bb1abf (patch)
tree54315ed3ffb0d4797e8b06b667b25c047accc697 /sys/src/libregexp/regcomp.c
parentf94167ebeebc108f393b3b2ec279cee2afae56e7 (diff)
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.
Diffstat (limited to 'sys/src/libregexp/regcomp.c')
-rw-r--r--sys/src/libregexp/regcomp.c18
1 files changed, 4 insertions, 14 deletions
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;
}