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,30 +162,36 @@ 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] == '>')) {
cap = walk(s2); r->b = dict_;
wrapped = c == '('; *dict_++ = 0;
if(wrapped) s2++, cap--; return s2;
while(s2 < cap) {
if(*s2 == '?') {
*dict_++ = *s2++;
reg = find_register(r, *s2);
if(reg < 0 && *s2 != '(')
r->key[r->ptr] = *s2, reg = r->ptr++;
*dict_++ = '0' + reg;
} else
*dict_++ = *s2++;
}
s2 += wrapped;
} }
cap = walk(s2);
wrapped = c == '(';
if(wrapped) s2++, cap--;
while(s2 < cap) {
if(*s2 == '?') {
*dict_++ = *s2++;
reg = find_register(r, *s2);
if(reg < 0 && *s2 != '(')
r->key[r->ptr] = *s2, reg = r->ptr++;
*dict_++ = '0' + reg;
} else
*dict_++ = *s2++;
}
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] == '>')) {
cap = walk(s2); *dict_++ = 0;
wrapped = c == '('; return s2;
if(wrapped) s2++, cap--;
while(s2 < cap) *dict_++ = *s2++;
s2 += wrapped;
} }
cap = walk(s2);
wrapped = c == '(';
if(wrapped) s2++, cap--;
while(s2 < cap) {
*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;