Break out of compilation early

This commit is contained in:
Devine Lu Linvega 2024-04-24 14:54:40 -07:00
parent dfe9b076dc
commit 3dbb23319e
1 changed files with 39 additions and 26 deletions

View File

@ -162,15 +162,21 @@ static char *
compile_rule(Rule *r, int id, char *src) compile_rule(Rule *r, int id, char *src)
{ {
int wrapped, reg; int wrapped, reg;
char c, *cap, *s, *s2; char c, *cap, *s2;
r->id = id, r->ptr = 0; r->id = id, r->ptr = 0;
/* left ==================================== */ /* left ==================================== */
r->a = dict_; r->a = dict_;
s2 = src; s2 = src;
while((c = *s2) && c == ' ') s2++; while((c = *s2) && c == ' ') s2++;
if(c != ')' && !(c == '<' && s2[1] == '>')) { if(c == ')' || (c == '<' && s2[1] == '>')) {
r->b = dict_;
*dict_++ = 0;
return s2;
}
cap = walk(s2); cap = walk(s2);
wrapped = c == '('; wrapped = c == '(';
if(wrapped) s2++, cap--; if(wrapped) s2++, cap--;
@ -185,7 +191,7 @@ compile_rule(Rule *r, int id, char *src)
*dict_++ = *s2++; *dict_++ = *s2++;
} }
s2 += wrapped; s2 += wrapped;
}
*dict_++ = 0; *dict_++ = 0;
src = s2; src = s2;
@ -193,23 +199,30 @@ compile_rule(Rule *r, int id, char *src)
r->b = dict_; r->b = dict_;
s2 = src; s2 = src;
while((c = *s2) && c == ' ') s2++; while((c = *s2) && c == ' ') s2++;
if(c != ')' && !(c == '<' && s2[1] == '>')) { if(c == ')' || (c == '<' && s2[1] == '>')) {
*dict_++ = 0;
return s2;
}
cap = walk(s2); cap = walk(s2);
wrapped = c == '('; wrapped = c == '(';
if(wrapped) s2++, cap--; if(wrapped) s2++, cap--;
while(s2 < cap) *dict_++ = *s2++; while(s2 < cap) {
s2 += wrapped; *dict_++ = *s2++;
} }
s2 += wrapped;
*dict_++ = 0; *dict_++ = 0;
src = s2; src = s2;
s = r->b; s2 = r->b;
while((c = *s++)) { /* right */ while((c = *s2++)) { /* right */
if(c == '?') { if(c == '?') {
reg = find_register(r, *s); reg = find_register(r, *s2);
if(reg >= 0) if(reg >= 0)
*s = '0' + reg; *s2 = '0' + reg;
} }
} }
return src; return src;