Housekeeping

This commit is contained in:
Devine Lu Linvega 2024-04-10 13:08:50 -07:00
parent a966253bd7
commit 0b2d71a4d9
1 changed files with 11 additions and 10 deletions

View File

@ -94,7 +94,7 @@ put_reg(char r)
} }
static char * static char *
match_rule(char *p, Rule *r) match_rule(Rule *r, char *p)
{ {
int i; int i;
char c, *a = r->a, *b = p; char c, *a = r->a, *b = p;
@ -144,10 +144,11 @@ parse_frag(char *s)
} }
static int static int
write(Rule *r, char last, char *res){ write(Rule *r, char last, char *res)
{
char cc, *b = r->b; char cc, *b = r->b;
if(!*b && last == ' ') outp_--; if(!*b && last == ' ') outp_--;
while((cc = *b++)) while((cc = *b++))
if(cc == '?') if(cc == '?')
put_reg(*b++); put_reg(*b++);
else else
@ -162,7 +163,7 @@ rewrite(void)
while((c = *p) && c <= ' ') p++; while((c = *p) && c <= ' ') p++;
while((c = *p)) { while((c = *p)) {
if(spacer(last)) { if(spacer(last)) {
Rule *r = NULL, lambda; Rule *r;
if(p[0] == '<' && p[1] == '>') { if(p[0] == '<' && p[1] == '>') {
r = rules_++; r = rules_++;
r->id = rules_ - rules - 1; r->id = rules_ - rules - 1;
@ -170,15 +171,15 @@ rewrite(void)
return commit_rule(r, p, 1); return commit_rule(r, p, 1);
} }
if(p[0] == '?' && p[1] == '(') { if(p[0] == '?' && p[1] == '(') {
r = &lambda; Rule lambda;
p += 2, r->a = dict_, p = parse_frag(p), r->b = dict_, p = parse_frag(p); p += 2, lambda.a = dict_, p = parse_frag(p), lambda.b = dict_, p = parse_frag(p);
p++; p++;
while((c = *p) && c <= ' ') p++; while((c = *p) && c <= ' ') p++;
if((res = match_rule(p, r)) != NULL) if((res = match_rule(&lambda, p)) != NULL)
return write(r, last, res); return write(&lambda, last, res);
} }
for(r = rules; r < rules_; r++) for(r = rules; r < rules_; r++)
if((res = match_rule(p, r)) != NULL) if((res = match_rule(r, p)) != NULL)
return write(r, last, res); return write(r, last, res);
} }
*outp_++ = last = c; *outp_++ = last = c;