Merged rule compilation for left side
This commit is contained in:
parent
97d406c3a8
commit
dfe9b076dc
25
src/modal.c
25
src/modal.c
|
@ -161,7 +161,7 @@ find_register(Rule *r, char reg)
|
|||
static char *
|
||||
compile_rule(Rule *r, int id, char *src)
|
||||
{
|
||||
int wrapped;
|
||||
int wrapped, reg;
|
||||
char c, *cap, *s, *s2;
|
||||
r->id = id, r->ptr = 0;
|
||||
|
||||
|
@ -174,22 +174,21 @@ compile_rule(Rule *r, int id, char *src)
|
|||
cap = walk(s2);
|
||||
wrapped = c == '(';
|
||||
if(wrapped) s2++, cap--;
|
||||
while(s2 < cap) *dict_++ = *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;
|
||||
}
|
||||
*dict_++ = 0;
|
||||
src = s2;
|
||||
|
||||
s = r->a;
|
||||
while((c = *s++)) { /* left */
|
||||
if(c == '?') {
|
||||
int reg = find_register(r, *s);
|
||||
if(reg < 0 && *s != '(')
|
||||
r->key[r->ptr] = *s, reg = r->ptr++;
|
||||
*s = '0' + reg;
|
||||
}
|
||||
}
|
||||
|
||||
/* right ==================================== */
|
||||
|
||||
r->b = dict_;
|
||||
|
@ -208,7 +207,7 @@ compile_rule(Rule *r, int id, char *src)
|
|||
s = r->b;
|
||||
while((c = *s++)) { /* right */
|
||||
if(c == '?') {
|
||||
int reg = find_register(r, *s);
|
||||
reg = find_register(r, *s);
|
||||
if(reg >= 0)
|
||||
*s = '0' + reg;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue