Merged all bind helpers
This commit is contained in:
parent
36f9bfdaee
commit
04bf0f67d4
28
src/modal.c
28
src/modal.c
|
@ -31,22 +31,21 @@ walk(char *s)
|
|||
}
|
||||
|
||||
static int
|
||||
compare(char *a, char *b)
|
||||
bind(int id, char *b)
|
||||
{
|
||||
char *aa = walk(a), *bb = walk(b);
|
||||
if(regs[id]) {
|
||||
char *a = regs[id], *aa = walk(a), *bb = walk(b);
|
||||
while(a < aa && b < bb)
|
||||
if(*a++ != *b++) return 0;
|
||||
} else if(id == ':') {
|
||||
char *bb = walk(b);
|
||||
if(*b == '(') b++, --bb;
|
||||
while(b < bb) putc(*(b++), stdout);
|
||||
} else
|
||||
regs[id] = b;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
call(char *s)
|
||||
{
|
||||
char *ss = walk(s);
|
||||
if(*s == '(') s++, --ss;
|
||||
while(s < ss) putc(*(s++), stdout);
|
||||
}
|
||||
|
||||
static char *
|
||||
match(char *p, Rule *r)
|
||||
{
|
||||
|
@ -57,14 +56,7 @@ match(char *p, Rule *r)
|
|||
regs[i] = 0;
|
||||
while((c = *a)) {
|
||||
if(c == '?') {
|
||||
int id = (int)*(++a);
|
||||
if(regs[id]) {
|
||||
if(!compare(regs[id], b))
|
||||
return NULL;
|
||||
} else if(id == ':')
|
||||
call(b);
|
||||
else
|
||||
regs[id] = b;
|
||||
if(!bind(*(++a), b)) return NULL;
|
||||
a++, b = walk(b);
|
||||
}
|
||||
if(!*a && spacer(*b)) return b;
|
||||
|
|
Loading…
Reference in New Issue