extmod: Pull in upstream changes to re1.5; fixes bugs with regex errors.
This commit is contained in:
parent
b4c9a25eab
commit
8dead2a6c6
@ -129,6 +129,7 @@ const char *_compilecode(const char *re, ByteProg *prog)
|
|||||||
|
|
||||||
prog->bytelen = pc;
|
prog->bytelen = pc;
|
||||||
re = _compilecode(re + 1, prog);
|
re = _compilecode(re + 1, prog);
|
||||||
|
if (re == NULL || *re != ')') return NULL; // error, or no matching paren
|
||||||
pc = prog->bytelen;
|
pc = prog->bytelen;
|
||||||
|
|
||||||
EMIT(pc++, Save);
|
EMIT(pc++, Save);
|
||||||
@ -138,12 +139,14 @@ const char *_compilecode(const char *re, ByteProg *prog)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case '?':
|
case '?':
|
||||||
|
if (pc == term) return NULL; // nothing to repeat
|
||||||
insert_code(code, term, 2, &pc);
|
insert_code(code, term, 2, &pc);
|
||||||
EMIT(term, Split);
|
EMIT(term, Split);
|
||||||
EMIT(term + 1, REL(term, pc));
|
EMIT(term + 1, REL(term, pc));
|
||||||
prog->len++;
|
prog->len++;
|
||||||
break;
|
break;
|
||||||
case '*':
|
case '*':
|
||||||
|
if (pc == term) return NULL; // nothing to repeat
|
||||||
insert_code(code, term, 2, &pc);
|
insert_code(code, term, 2, &pc);
|
||||||
EMIT(pc, Jmp);
|
EMIT(pc, Jmp);
|
||||||
EMIT(pc + 1, REL(pc, term));
|
EMIT(pc + 1, REL(pc, term));
|
||||||
@ -158,6 +161,7 @@ const char *_compilecode(const char *re, ByteProg *prog)
|
|||||||
prog->len += 2;
|
prog->len += 2;
|
||||||
break;
|
break;
|
||||||
case '+':
|
case '+':
|
||||||
|
if (pc == term) return NULL; // nothing to repeat
|
||||||
if (re[1] == '?') {
|
if (re[1] == '?') {
|
||||||
EMIT(pc, Split);
|
EMIT(pc, Split);
|
||||||
re++;
|
re++;
|
||||||
@ -217,7 +221,8 @@ int re1_5_compilecode(ByteProg *prog, const char *re)
|
|||||||
prog->insts[prog->bytelen++] = 0;
|
prog->insts[prog->bytelen++] = 0;
|
||||||
prog->len++;
|
prog->len++;
|
||||||
|
|
||||||
_compilecode(re, prog);
|
re = _compilecode(re, prog);
|
||||||
|
if (re == NULL || *re) return 1;
|
||||||
|
|
||||||
prog->insts[prog->bytelen++] = Save;
|
prog->insts[prog->bytelen++] = Save;
|
||||||
prog->insts[prog->bytelen++] = 1;
|
prog->insts[prog->bytelen++] = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user