aboutsummaryrefslogtreecommitdiff
path: root/extmod/re1.5
diff options
context:
space:
mode:
authorPaul Sokolovsky2014-10-16 13:56:13 +0300
committerPaul Sokolovsky2014-10-17 22:25:18 +0300
commit297d8469b8fcaa072630c9561695edb001d96232 (patch)
tree04e7bfb9ddb60a8a8b84feb59c95c9d7cf4627b4 /extmod/re1.5
parent391db8669b77e50eebe4d1583749430a3549fab7 (diff)
modure: Update to re1.5 v0.6.1, fixed and extended character class support.
Diffstat (limited to 'extmod/re1.5')
-rw-r--r--extmod/re1.5/charclass.c8
-rw-r--r--extmod/re1.5/compilecode.c10
-rw-r--r--extmod/re1.5/dumpcode.c8
-rw-r--r--extmod/re1.5/re1.5.h1
-rw-r--r--extmod/re1.5/recursiveloop.c1
5 files changed, 20 insertions, 8 deletions
diff --git a/extmod/re1.5/charclass.c b/extmod/re1.5/charclass.c
index c9f617592..c9df40375 100644
--- a/extmod/re1.5/charclass.c
+++ b/extmod/re1.5/charclass.c
@@ -3,9 +3,11 @@
int _re1_5_classmatch(const char *pc, const char *sp)
{
// pc points to "cnt" byte after opcode
+ int is_positive = (pc[-1] == Class);
int cnt = *pc++;
while (cnt--) {
- if (!(*sp >= *pc && *sp <= pc[1])) return 0;
+ if (*sp >= *pc && *sp <= pc[1]) return is_positive;
+ pc += 2;
}
- return 1;
-} \ No newline at end of file
+ return !is_positive;
+}
diff --git a/extmod/re1.5/compilecode.c b/extmod/re1.5/compilecode.c
index a7942b121..2ed38d02c 100644
--- a/extmod/re1.5/compilecode.c
+++ b/extmod/re1.5/compilecode.c
@@ -48,6 +48,7 @@ int re1_5_sizecode(const char *re)
case '[': {
pc += 2;
re++;
+ if (*re == '^') re++;
while (*re != ']') {
if (!*re) return -1;
if (re[1] == '-') {
@@ -91,10 +92,15 @@ const char *_compilecode(const char *re, ByteProg *prog)
case '[': {
int cnt;
term = pc;
- EMIT(pc++, Class);
+ re++;
+ if (*re == '^') {
+ EMIT(pc++, ClassNot);
+ re++;
+ } else {
+ EMIT(pc++, Class);
+ }
pc++; // Skip # of pair byte
prog->len++;
- re++;
for (cnt = 0; *re != ']'; re++, cnt++) {
if (!*re) return NULL;
EMIT(pc++, *re);
diff --git a/extmod/re1.5/dumpcode.c b/extmod/re1.5/dumpcode.c
index ca41cfeda..1e2377675 100644
--- a/extmod/re1.5/dumpcode.c
+++ b/extmod/re1.5/dumpcode.c
@@ -32,9 +32,11 @@ void re1_5_dumpcode(ByteProg *prog)
case Any:
printf("any\n");
break;
- case Class: {
- int num = code[pc++];
- printf("class %d", num);
+ case Class:
+ case ClassNot: {
+ int num = code[pc];
+ printf("class%s %d", (code[pc - 1] == ClassNot ? "not" : ""), num);
+ pc++;
while (num--) {
printf(" 0x%02x-0x%02x", code[pc], code[pc + 1]);
pc += 2;
diff --git a/extmod/re1.5/re1.5.h b/extmod/re1.5/re1.5.h
index ac41bab8f..d8c1cf3e5 100644
--- a/extmod/re1.5/re1.5.h
+++ b/extmod/re1.5/re1.5.h
@@ -81,6 +81,7 @@ enum /* Inst.opcode */
Char = CONSUMERS,
Any,
Class,
+ ClassNot,
ASSERTS = 0x50,
Bol = ASSERTS,
diff --git a/extmod/re1.5/recursiveloop.c b/extmod/re1.5/recursiveloop.c
index 26c6da43d..f133b5d9b 100644
--- a/extmod/re1.5/recursiveloop.c
+++ b/extmod/re1.5/recursiveloop.c
@@ -24,6 +24,7 @@ recursiveloop(char *pc, const char *sp, Subject *input, const char **subp, int n
sp++;
continue;
case Class:
+ case ClassNot:
if (!_re1_5_classmatch(pc, sp))
return 0;
pc += *(unsigned char*)pc * 2 + 1;