From 3837d0364bf4da659cf7c205300caeb14d6c80e9 Mon Sep 17 00:00:00 2001 From: Kyryl Melekhin Date: Sun, 18 Jul 2021 22:33:09 +0000 Subject: [PATCH] drop named classes because of no new functionality --- README | 2 +- pike.c | 40 +--------------------------------------- test.sh | 15 +++------------ 3 files changed, 5 insertions(+), 52 deletions(-) diff --git a/README b/README index 24a9e53..fdafa67 100644 --- a/README +++ b/README @@ -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 ================== diff --git a/pike.c b/pike.c index d0c26d1..2b1ed9d 100644 --- a/pike.c +++ b/pike.c @@ -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; in; 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++) diff --git a/test.sh b/test.sh index 8ca4a2c..ee4b4eb 100755 --- a/test.sh +++ b/test.sh @@ -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)