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 *
|
static Rule *
|
||||||
find_rule(char *s)
|
find_rule(char *s, char *cap)
|
||||||
{
|
{
|
||||||
Rule *r = rules;
|
Rule *r = rules;
|
||||||
|
if(*s == '(') s++, cap--;
|
||||||
while(r < rules_) {
|
while(r < rules_) {
|
||||||
char *ss = s, *a = r->a;
|
char *ss = s, *a = r->a;
|
||||||
while(*ss++ == *a++)
|
while(*ss++ == *a++)
|
||||||
if(!*a) return r;
|
if(!*a) return r;
|
||||||
r++;
|
r++;
|
||||||
}
|
}
|
||||||
return NULL;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -227,12 +228,12 @@ rewrite(void)
|
||||||
}
|
}
|
||||||
/* phase: undefine */
|
/* phase: undefine */
|
||||||
if(c == '>' && s[1] == '<') {
|
if(c == '>' && s[1] == '<') {
|
||||||
s += 2;
|
s += 2, cap = walk(s);
|
||||||
while(*s == ' ') 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);
|
if(!quiet && r->a) fprintf(stderr, ">< (%s)\n", r->a);
|
||||||
while(*s == ' ') s++;
|
while(*cap == ' ') cap++;
|
||||||
return write_rule(NULL, s);
|
return write_rule(NULL, cap);
|
||||||
}
|
}
|
||||||
/* phase: match */
|
/* phase: match */
|
||||||
for(r = rules; r < rules_; r++)
|
for(r = rules; r < rules_; r++)
|
||||||
|
|
Loading…
Reference in New Issue