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