restructure main loop
This commit is contained in:
parent
6c163d8eb0
commit
0448ebed7a
1 changed files with 15 additions and 15 deletions
30
regex.c
30
regex.c
|
@ -151,7 +151,18 @@ bool regex_match(char *haystack, char *needle)
|
||||||
if (!bv[st])
|
if (!bv[st])
|
||||||
continue;
|
continue;
|
||||||
fprintf(stderr, "prepr %lu: \"%s\"\n", st, needle + st);
|
fprintf(stderr, "prepr %lu: \"%s\"\n", st, needle + st);
|
||||||
if (needle[st] == '|')
|
if (needle[st] == '(')
|
||||||
|
{
|
||||||
|
// at start of group, look at variants and quantifier
|
||||||
|
for (var = needle + st + 1; *var && *var != ')'; var = next_var(var))
|
||||||
|
bv[var - needle] = true;
|
||||||
|
if (*var == ')')
|
||||||
|
var++;
|
||||||
|
q = quant(*var);
|
||||||
|
if (strchr("*?", q))
|
||||||
|
bv[var + 1 - needle] = true;
|
||||||
|
}
|
||||||
|
else if (needle[st] == '|')
|
||||||
{
|
{
|
||||||
// at end of variant, look at end of group
|
// at end of variant, look at end of group
|
||||||
bv[st] = false;
|
bv[st] = false;
|
||||||
|
@ -171,7 +182,7 @@ bool regex_match(char *haystack, char *needle)
|
||||||
fprintf(stderr, "quant %c\n", q);
|
fprintf(stderr, "quant %c\n", q);
|
||||||
fprintf(stderr, "suffix \"%s\"\n", needle + (q ? st + 2 : st + 1));
|
fprintf(stderr, "suffix \"%s\"\n", needle + (q ? st + 2 : st + 1));
|
||||||
nneedl = start_of_group(needle, needle + st);
|
nneedl = start_of_group(needle, needle + st);
|
||||||
if ((q == '+' || q == '*') && !bv[nneedl - needle])
|
if (strchr("+*", q) && !bv[nneedl - needle])
|
||||||
{
|
{
|
||||||
// spicy: if the quantifier allows multiple occurences, we have to activate a previous state
|
// spicy: if the quantifier allows multiple occurences, we have to activate a previous state
|
||||||
fprintf(stderr, "start of group: \"%s\"\n", nneedl);
|
fprintf(stderr, "start of group: \"%s\"\n", nneedl);
|
||||||
|
@ -181,23 +192,12 @@ bool regex_match(char *haystack, char *needle)
|
||||||
else
|
else
|
||||||
bv[nneedl - needle] = false;
|
bv[nneedl - needle] = false;
|
||||||
}
|
}
|
||||||
else if (needle[st] == '(')
|
|
||||||
{
|
|
||||||
// at start of group, look at variants and quantifier
|
|
||||||
for (var = needle + st + 1; *var && *var != ')'; var = next_var(var))
|
|
||||||
bv[var - needle] = true;
|
|
||||||
if (*var == ')')
|
|
||||||
var++;
|
|
||||||
q = quant(*var);
|
|
||||||
if (q == '*' || q == '?')
|
|
||||||
bv[var + 1 - needle] = true;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// check if current needle is optional
|
// check if current needle is optional
|
||||||
nneedl = next_char(needle + st);
|
nneedl = next_char(needle + st);
|
||||||
q = *nneedl;
|
q = *nneedl;
|
||||||
if (q == '*' || q == '?')
|
if (strchr("?*", q))
|
||||||
bv[nneedl + 1 - needle] = true;
|
bv[nneedl + 1 - needle] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ bool regex_match(char *haystack, char *needle)
|
||||||
na = false;
|
na = false;
|
||||||
if (q)
|
if (q)
|
||||||
nneedl++;
|
nneedl++;
|
||||||
if (q == '*' || q == '+')
|
if (strchr("*+", q))
|
||||||
bv[st-1] = true;
|
bv[st-1] = true;
|
||||||
bv[nneedl - needle] = true;
|
bv[nneedl - needle] = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue