Completed split from match and apply
This commit is contained in:
parent
6d10bb3b66
commit
8cb22a9966
16
src/modal.c
16
src/modal.c
|
@ -6,7 +6,7 @@ typedef struct {
|
||||||
} Rule;
|
} Rule;
|
||||||
|
|
||||||
static int flip, quiet, cycles = 0x10000;
|
static int flip, quiet, cycles = 0x10000;
|
||||||
static Rule rules[0x1000], *rules_ = rules, lambda;
|
static Rule rules[0x1000], *rules_ = rules;
|
||||||
static char dict[0x8000], *dict_ = dict, empty;
|
static char dict[0x8000], *dict_ = dict, empty;
|
||||||
static char bank_a[0x4000], *src_ = bank_a;
|
static char bank_a[0x4000], *src_ = bank_a;
|
||||||
static char bank_b[0x4000], *dst_ = bank_b;
|
static char bank_b[0x4000], *dst_ = bank_b;
|
||||||
|
@ -136,7 +136,6 @@ apply_rule(Rule *r, char **regs, char *s)
|
||||||
{
|
{
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
char c, *b = r->b, *origin = dst_, *reg;
|
char c, *b = r->b, *origin = dst_, *reg;
|
||||||
if((s = match_rule(r, regs, s)) == NULL) return 0;
|
|
||||||
/* phase: write rule */
|
/* phase: write rule */
|
||||||
while((c = *b++)) {
|
while((c = *b++)) {
|
||||||
if(c == '?') {
|
if(c == '?') {
|
||||||
|
@ -204,7 +203,7 @@ compile_rule(Rule *r, int id, char *src)
|
||||||
static int
|
static int
|
||||||
rewrite(void)
|
rewrite(void)
|
||||||
{
|
{
|
||||||
char c, last = 0, *cap, *s = src_, *regs[0x08];
|
char c, last = 0, *cap, *s = src_, *regs[0x08], *res;
|
||||||
while(*s == ' ') s++;
|
while(*s == ' ') s++;
|
||||||
while((c = *s)) {
|
while((c = *s)) {
|
||||||
if(spacer(last)) {
|
if(spacer(last)) {
|
||||||
|
@ -218,15 +217,16 @@ rewrite(void)
|
||||||
}
|
}
|
||||||
/* phase: lambda */
|
/* phase: lambda */
|
||||||
if(c == '?' && s[1] == '(') {
|
if(c == '?' && s[1] == '(') {
|
||||||
cap = walk(s + 1);
|
Rule lambda;
|
||||||
compile_rule(&lambda, -1, s + 2);
|
cap = walk(s + 1), compile_rule(&lambda, -1, s + 2), s = cap;
|
||||||
s = cap;
|
|
||||||
while(*s == ' ') s++;
|
while(*s == ' ') s++;
|
||||||
return apply_rule(&lambda, regs, s);
|
if((res = match_rule(&lambda, regs, s)) != NULL)
|
||||||
|
return apply_rule(&lambda, regs, res);
|
||||||
}
|
}
|
||||||
/* phase: match */
|
/* phase: match */
|
||||||
for(r = rules; r < rules_; r++)
|
for(r = rules; r < rules_; r++)
|
||||||
if(apply_rule(r, regs, s)) return 1;
|
if((res = match_rule(r, regs, s)) != NULL)
|
||||||
|
return apply_rule(r, regs, res);
|
||||||
}
|
}
|
||||||
*dst_++ = last = c;
|
*dst_++ = last = c;
|
||||||
s++;
|
s++;
|
||||||
|
|
Loading…
Reference in New Issue