summaryrefslogtreecommitdiffstatshomepage
path: root/extmod/re1.5/compilecode.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-10-15 04:43:13 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-10-15 04:44:07 +0300
commit95908b0f50e26fe2c90687966b60a0cf195f71de (patch)
tree4bdbe99b47accb07ae45e50a8944be6a67679313 /extmod/re1.5/compilecode.c
parentd27c0bb3aa3e571a9efc43fa54c16b85e91a7b03 (diff)
downloadmicropython-95908b0f50e26fe2c90687966b60a0cf195f71de.tar.gz
micropython-95908b0f50e26fe2c90687966b60a0cf195f71de.zip
modure: Update to re1.5 v0.6, support for char sets/classes ([a-c]).
Diffstat (limited to 'extmod/re1.5/compilecode.c')
-rw-r--r--extmod/re1.5/compilecode.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/extmod/re1.5/compilecode.c b/extmod/re1.5/compilecode.c
index 5b5d28c2a0..a7942b1216 100644
--- a/extmod/re1.5/compilecode.c
+++ b/extmod/re1.5/compilecode.c
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-#include "regexp.h"
+#include "re1.5.h"
static void insert_code(char *code, int at, int num, int *pc)
{
@@ -45,6 +45,18 @@ int re1_5_sizecode(const char *re)
break;
case ')':
break;
+ case '[': {
+ pc += 2;
+ re++;
+ while (*re != ']') {
+ if (!*re) return -1;
+ if (re[1] == '-') {
+ re += 2;
+ }
+ pc += 2;
+ re++;
+ }
+ }
}
}
@@ -76,6 +88,24 @@ const char *_compilecode(const char *re, ByteProg *prog)
EMIT(pc++, Any);
prog->len++;
break;
+ case '[': {
+ int cnt;
+ term = pc;
+ EMIT(pc++, Class);
+ pc++; // Skip # of pair byte
+ prog->len++;
+ re++;
+ for (cnt = 0; *re != ']'; re++, cnt++) {
+ if (!*re) return NULL;
+ EMIT(pc++, *re);
+ if (re[1] == '-') {
+ re += 2;
+ }
+ EMIT(pc++, *re);
+ }
+ EMIT(term + 1, cnt);
+ break;
+ }
case '(':
term = pc;