diff --git a/src/modal.c b/src/modal.c index d6546bd..6f317a5 100644 --- a/src/modal.c +++ b/src/modal.c @@ -148,24 +148,6 @@ apply_rule(Rule *r, char *s) return 0; } -static char * -parse_frag(char *s) -{ - char c, *cap; - while((c = *s) && c == ' ') s++; - if(c != ')' && !(c == '<' && s[1] == '>')) { - cap = walk(s); - if(c == '(') { - s++; - while(s < cap - 1) *dict_++ = *s++; - s++; - } else - while(s < cap) *dict_++ = *s++; - } - *dict_++ = 0; - return s; -} - static int find_register(Rule *r, char reg) { @@ -179,9 +161,25 @@ find_register(Rule *r, char reg) static char * compile_rule(Rule *r, int id, char *src) { - char c, *s; + char c, *cap, *s, *s2; r->id = id, r->ptr = 0; - r->a = dict_, src = parse_frag(src); + + /* left */ + r->a = dict_; + s2 = src; + while((c = *s2) && c == ' ') s2++; + if(c != ')' && !(c == '<' && s2[1] == '>')) { + cap = walk(s2); + if(c == '(') { + s2++; + while(s2 < cap - 1) *dict_++ = *s2++; + s2++; + } else + while(s2 < cap) *dict_++ = *s2++; + } + *dict_++ = 0; + src = s2; + s = r->a; while((c = *s++)) { /* left */ if(c == '?') { @@ -191,7 +189,23 @@ compile_rule(Rule *r, int id, char *src) *s = '0' + reg; } } - r->b = dict_, src = parse_frag(src); + + /* right */ + r->b = dict_; + s2 = src; + while((c = *s2) && c == ' ') s2++; + if(c != ')' && !(c == '<' && s2[1] == '>')) { + cap = walk(s2); + if(c == '(') { + s2++; + while(s2 < cap - 1) *dict_++ = *s2++; + s2++; + } else + while(s2 < cap) *dict_++ = *s2++; + } + *dict_++ = 0; + src = s2; + s = r->b; while((c = *s++)) { /* right */ if(c == '?') {