Unwrap rules during match
This commit is contained in:
parent
37effa5dfd
commit
541e8937b0
13
src/modal.c
13
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++)
|
||||
|
|
Loading…
Reference in New Issue