diff --git a/src/modal.c b/src/modal.c index 6f317a5..eace724 100644 --- a/src/modal.c +++ b/src/modal.c @@ -161,21 +161,21 @@ find_register(Rule *r, char reg) static char * compile_rule(Rule *r, int id, char *src) { + int wrapped; char c, *cap, *s, *s2; r->id = id, r->ptr = 0; - /* left */ + /* 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++; + wrapped = c == '('; + if(wrapped) s2++, cap--; + while(s2 < cap) *dict_++ = *s2++; + s2 += wrapped; } *dict_++ = 0; src = s2; @@ -190,18 +190,17 @@ compile_rule(Rule *r, int id, char *src) } } - /* right */ + /* 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++; + wrapped = c == '('; + if(wrapped) s2++, cap--; + while(s2 < cap) *dict_++ = *s2++; + s2 += wrapped; } *dict_++ = 0; src = s2;