Isolated rule finding

This commit is contained in:
Devine Lu Linvega 2024-04-25 11:08:14 -07:00
parent 8cb22a9966
commit f28444f60e
1 changed files with 6 additions and 4 deletions

View File

@ -203,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], *res; char c, last = 0, *cap, *s = src_, *regs[0x08], *res = NULL;
while(*s == ' ') s++; while(*s == ' ') s++;
while((c = *s)) { while((c = *s)) {
if(spacer(last)) { if(spacer(last)) {
@ -220,13 +220,15 @@ rewrite(void)
Rule lambda; Rule lambda;
cap = walk(s + 1), compile_rule(&lambda, -1, s + 2), s = cap; cap = walk(s + 1), compile_rule(&lambda, -1, s + 2), s = cap;
while(*s == ' ') s++; while(*s == ' ') s++;
if((res = match_rule(&lambda, regs, s)) != NULL) if((res = match_rule(&lambda, regs, s)))
return apply_rule(&lambda, regs, res); return apply_rule(&lambda, regs, res);
} }
/* phase: match */ /* phase: match */
for(r = rules; r < rules_; r++) for(r = rules; r < rules_; r++)
if((res = match_rule(r, regs, s)) != NULL) if((res = match_rule(r, regs, s))) break;
return apply_rule(r, regs, res); /* phase: apply */
if(res)
return apply_rule(r, regs, res);
} }
*dst_++ = last = c; *dst_++ = last = c;
s++; s++;