Housekeeping
This commit is contained in:
parent
8bb661ced0
commit
c73b9f0ad7
14
src/modal.c
14
src/modal.c
|
@ -14,7 +14,7 @@ static char bank_b[0x4000], *dst_ = bank_b;
|
||||||
/* clang-format off */
|
/* clang-format off */
|
||||||
|
|
||||||
#define spacer(c) (c <= ' ' || c == '(' || c == ')')
|
#define spacer(c) (c <= ' ' || c == '(' || c == ')')
|
||||||
#define get_reg(x) { regid = x; for(i = 0; i < regs_ptr; i++) if(regs_key[i] == regid) { reg = regs_val[i]; break; } }
|
#define get_reg(x) { regid = x; for(i = 0; i < rptr; i++) if(rkey[i] == regid) { reg = rval[i]; break; } }
|
||||||
|
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
|
||||||
|
@ -76,10 +76,9 @@ write_reg(char r, char *reg)
|
||||||
*dst_++ = ' ';
|
*dst_++ = ' ';
|
||||||
*dst_++ = '(', reg++, depth++;
|
*dst_++ = '(', reg++, depth++;
|
||||||
}
|
}
|
||||||
} else { /* token */
|
} else /* token */
|
||||||
while((c = *reg++) && !spacer(c))
|
while((c = *reg++) && !spacer(c))
|
||||||
*dst_++ = c, *dst_++ = ' ', *dst_++ = '(', depth++;
|
*dst_++ = c, *dst_++ = ' ', *dst_++ = '(', depth++;
|
||||||
}
|
|
||||||
for(i = 0; i < depth; i++) *dst_++ = ')';
|
for(i = 0; i < depth; i++) *dst_++ = ')';
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -111,8 +110,8 @@ write_rule(Rule *r, char *s, int create)
|
||||||
static int
|
static int
|
||||||
apply_rule(Rule *r, char *s)
|
apply_rule(Rule *r, char *s)
|
||||||
{
|
{
|
||||||
int i, regid, regs_ptr = 0;
|
int i, regid, rptr = 0;
|
||||||
char c, *a = r->a, regs_key[0x10], *regs_val[0x10];
|
char c, *a = r->a, rkey[0x10], *rval[0x10];
|
||||||
while((c = *a)) { /* phase: match rule */
|
while((c = *a)) { /* phase: match rule */
|
||||||
if(c == '?') {
|
if(c == '?') {
|
||||||
char *pcap = walk(s), *reg = NULL;
|
char *pcap = walk(s), *reg = NULL;
|
||||||
|
@ -122,7 +121,7 @@ apply_rule(Rule *r, char *s)
|
||||||
while(reg < rcap || pp < pcap)
|
while(reg < rcap || pp < pcap)
|
||||||
if(*reg++ != *pp++) return 0;
|
if(*reg++ != *pp++) return 0;
|
||||||
} else /* reg set */
|
} else /* reg set */
|
||||||
regs_key[regs_ptr] = regid, regs_val[regs_ptr++] = s;
|
rkey[rptr] = regid, rval[rptr++] = s;
|
||||||
a++, s = pcap;
|
a++, s = pcap;
|
||||||
if(!spacer(*a))
|
if(!spacer(*a))
|
||||||
while((c = *a) && !spacer(c)) a++;
|
while((c = *a) && !spacer(c)) a++;
|
||||||
|
@ -187,8 +186,7 @@ rewrite(void)
|
||||||
return write_rule(r, s, 1);
|
return write_rule(r, s, 1);
|
||||||
}
|
}
|
||||||
if(c == '?' && s[1] == '(') { /* lambda */
|
if(c == '?' && s[1] == '(') { /* lambda */
|
||||||
cap = walk(s + 1);
|
cap = walk(s + 1), lambda.id = -1;
|
||||||
lambda.id = -1;
|
|
||||||
lambda.a = dict_, s = parse_frag(s + 2);
|
lambda.a = dict_, s = parse_frag(s + 2);
|
||||||
lambda.b = dict_, parse_frag(s), s = cap;
|
lambda.b = dict_, parse_frag(s), s = cap;
|
||||||
while(*s == ' ') s++;
|
while(*s == ' ') s++;
|
||||||
|
|
Loading…
Reference in New Issue