diff --git a/src/modal.c b/src/modal.c index 081bb87..7b3dcdd 100644 --- a/src/modal.c +++ b/src/modal.c @@ -190,16 +190,17 @@ compile_rule(Rule *r, int id, char *src) } static Rule * -find_rule(char *s) +find_rule(char *s, char *cap) { Rule *r = rules; + if(*s == '(') s++, cap--; while(r < rules_) { char *ss = s, *a = r->a; while(*ss++ == *a++) if(!*a) return r; r++; } - return NULL; + return r; } static int @@ -227,12 +228,12 @@ rewrite(void) } /* phase: undefine */ if(c == '>' && s[1] == '<') { - s += 2; + s += 2, cap = walk(s); while(*s == ' ') s++; - r = find_rule(s), r->a = 0, s = walk(s); + r = find_rule(s, cap), r->a = 0; if(!quiet && r->a) fprintf(stderr, ">< (%s)\n", r->a); - while(*s == ' ') s++; - return write_rule(NULL, s); + while(*cap == ' ') cap++; + return write_rule(NULL, cap); } /* phase: match */ for(r = rules; r < rules_; r++)