diff --git a/src/modal.c b/src/modal.c index 571d8ec..32c3843 100644 --- a/src/modal.c +++ b/src/modal.c @@ -176,11 +176,13 @@ find_register(Rule *r, char reg) return -1; } -static void -compile_rule(Rule *r) +static char * +compile_rule(Rule *r, char *src) { int i; char c, *s; + r->a = dict_, src = parse_frag(src); + r->b = dict_, src = parse_frag(src); r->ptr = 0; s = r->a; while((c = *s++)) { /* left */ @@ -199,6 +201,7 @@ compile_rule(Rule *r) *s = '0' + reg; } } + return src; } static int @@ -211,17 +214,15 @@ rewrite(void) Rule *r = NULL; if(c == '<' && s[1] == '>') { /* rule */ r = rules_++, r->id = rules_ - rules - 1; - r->a = dict_, s = parse_frag(s + 2); - r->b = dict_, s = parse_frag(s); - compile_rule(r); + s = compile_rule(r, s + 2); while(*s == ' ') s++; return write_rule(r, s, 1); } if(c == '?' && s[1] == '(') { /* lambda */ - cap = walk(s + 1), lambda.id = -1; - lambda.a = dict_, s = parse_frag(s + 2); - lambda.b = dict_, parse_frag(s), s = cap; - compile_rule(&lambda); + cap = walk(s + 1); + r = &lambda, r->id = -1; + compile_rule(r, s + 2); + s = cap; while(*s == ' ') s++; return apply_rule(&lambda, s); }