drop named classes because of no new functionality

This commit is contained in:
Kyryl Melekhin
2021-07-18 22:33:09 +00:00
parent ea2252b079
commit 3837d0364b
3 changed files with 5 additions and 52 deletions

2
README
View File

@@ -41,7 +41,7 @@ TODO
* Support for matching flags like case-insensitive, dot matches all,
multiline, etc.
* Support for more assertions like \A, \Z.
* Support for wordend & wordbeg assertions
Author and License
==================

40
pike.c
View File

@@ -80,7 +80,6 @@ enum /* rinst.opcode */
CHAR = 1,
ANY,
CLASS,
NAMEDCLASS,
// Assert position
BOL,
EOL,
@@ -150,24 +149,6 @@ int re_classmatch(const int *pc, const char *sp)
return !is_positive;
}
int re_namedclassmatch(const int *pc, const char *sp)
{
// pc points to name of class
int off = (*pc >> 5) & 1;
if ((*pc | 0x20) == 'd') {
if (!(*sp >= '0' && *sp <= '9'))
off ^= 1;
} else if ((*pc | 0x20) == 's') {
if (!(*sp == ' ' || (*sp >= '\t' && *sp <= '\r')))
off ^= 1;
} else { // w
if (!((*sp >= 'A' && *sp <= 'Z') || (*sp >= 'a' && *sp <= 'z') ||
(*sp >= '0' && *sp <= '9') || *sp == '_'))
off ^= 1;
}
return off;
}
void re_dumpcode(rcode *prog)
{
int pc = 0;
@@ -207,9 +188,6 @@ void re_dumpcode(rcode *prog)
}
printf("\n");
break;
case NAMEDCLASS:
printf("namedclass %c\n", code[pc++]);
break;
case MATCH:
printf("match\n");
break;
@@ -239,16 +217,6 @@ static int _compilecode(const char **re_loc, rcode *prog, int sizecode)
case '\\':
re++;
if (!*re) goto syntax_error; // Trailing backslash
c = *re | 0x20;
if (c == 'd' || c == 's' || c == 'w') {
term = PC;
EMIT(PC++, NAMEDCLASS);
EMIT(PC++, *re);
prog->len++;
break;
}
if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z'))
goto unsupported_escape;
default:
term = PC;
EMIT(PC++, CHAR);
@@ -353,7 +321,6 @@ static int _compilecode(const char **re_loc, rcode *prog, int sizecode)
for (i = 0; i < size; i++)
switch (code[term]) {
case CLASS:
case NAMEDCLASS:
case JMP:
case SPLIT:
case RSPLIT:
@@ -591,7 +558,7 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
for(sp=s;; sp += l) {
if(clist->n == 0)
break;
gen++; uc_len(l, s)
gen++; uc_len(l, sp)
for(i=0; i<clist->n; i++) {
npc = clist->t[i].pc;
nsub = clist->t[i].sub;
@@ -614,11 +581,6 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
break;
npc += *(npc+1) * 2 + 2;
goto addthread;
case NAMEDCLASS:
if (!re_namedclassmatch(npc, sp))
break;
npc++;
goto addthread;
case MATCH:
matched = nsub;
for(i++; i < clist->n; i++)

15
test.sh
View File

@@ -14,12 +14,9 @@ abc+
([0-9]*)(?:([a-z]*)(?:[0-9]*))
(?:)
1?:
\\\d+
\\\s+
\\\w+
(\\\w+)\\\s+(\\\w+)
(\\\S+)\\\s+(\\\D+)
(([0-9]*)([a-z]*)\\\d*)
[0-9]+
[a-zA-Z0-9_]+
(([0-9]*)([a-z]*)[a-zA-Z0-9_]*)
[a]*
([yab]*)(e*)([cd])
([yab]*)(e*)([^y]?)$
@@ -64,10 +61,7 @@ abcccdef
1234hello568
1:
123abc456
123abc456
123abc_456 abc
ABC 123hello456 abc
ABC helloabc456 abc
123hello456
a
xyac
@@ -113,10 +107,7 @@ expect="\
(0,0)
(0,2)
(0,3)
(0,2)
(0,10)
(0,16)(0,3)(5,16)
(0,13)(0,3)(5,13)
(0,11)(0,11)(0,3)(3,8)
(0,1)
(1,4)(1,3)(3,3)(3,4)