Skip to content

Commit 64193c7

Browse files
committed
lib/re1.5: Add support for named classes in class sets.
Total code size change of this and previous commit: bare-arm: +0 +0.000% minimal x86: +0 +0.000% unix x64: +32 +0.004% standard stm32: +24 +0.006% PYBV10 cc3200: +16 +0.009% esp8266: +20 +0.003% GENERIC esp32: +44 +0.003% GENERIC[incl +8(data)] mimxrt: +32 +0.009% TEENSY40 renesas-ra: +24 +0.004% RA6M2_EK nrf: +0 +0.000% pca10040 rp2: +24 +0.005% PICO samd: +32 +0.012% ADAFRUIT_ITSYBITSY_M4_EXPRESS Addresses issue micropython#7920. Signed-off-by: Damien George <[email protected]>
1 parent bd86ce5 commit 64193c7

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

lib/re1.5/charclass.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ int _re1_5_classmatch(const char *pc, const char *sp)
66
int is_positive = (pc[-1] == Class);
77
int cnt = *pc++;
88
while (cnt--) {
9-
if (*sp >= *pc && *sp <= pc[1]) return is_positive;
9+
if (*pc == RE15_CLASS_NAMED_CLASS_INDICATOR) {
10+
if (_re1_5_namedclassmatch(pc + 1, sp)) {
11+
return is_positive;
12+
}
13+
} else {
14+
if (*sp >= *pc && *sp <= pc[1]) {
15+
return is_positive;
16+
}
17+
}
1018
pc += 2;
1119
}
1220
return !is_positive;

lib/re1.5/compilecode.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,21 @@ static const char *_compilecode(const char *re, ByteProg *prog, int sizecode)
6666
PC++; // Skip # of pair byte
6767
prog->len++;
6868
for (cnt = 0; *re != ']'; re++, cnt++) {
69-
if (*re == '\\') {
69+
char c = *re;
70+
if (c == '\\') {
7071
++re;
72+
c = *re;
73+
if (MATCH_NAMED_CLASS_CHAR(c)) {
74+
c = RE15_CLASS_NAMED_CLASS_INDICATOR;
75+
goto emit_char_pair;
76+
}
7177
}
72-
if (!*re) return NULL;
73-
EMIT(PC++, *re);
78+
if (!c) return NULL;
7479
if (re[1] == '-' && re[2] != ']') {
7580
re += 2;
7681
}
82+
emit_char_pair:
83+
EMIT(PC++, c);
7784
EMIT(PC++, *re);
7885
}
7986
EMIT_CHECKED(term + 1, cnt);

lib/re1.5/re1.5.h

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ struct Subject {
138138

139139
#define NON_ANCHORED_PREFIX 5
140140
#define HANDLE_ANCHORED(bytecode, is_anchored) ((is_anchored) ? (bytecode) + NON_ANCHORED_PREFIX : (bytecode))
141+
#define RE15_CLASS_NAMED_CLASS_INDICATOR 0
141142

142143
int re1_5_backtrack(ByteProg*, Subject*, const char**, int, int);
143144
int re1_5_pikevm(ByteProg*, Subject*, const char**, int, int);

0 commit comments

Comments
 (0)