Print result after the rewrite is entirely done

This commit is contained in:
Devine Lu Linvega 2024-05-21 21:29:41 -07:00
parent 155857c120
commit 9f8d78c9ec
2 changed files with 9 additions and 9 deletions

View File

@ -176,7 +176,7 @@ write_reg(char r, char *reg)
} }
static int static int
write_tail(char *s) write_tail(char *s, Rule *r)
{ {
while((*dst_++ = *s++)) while((*dst_++ = *s++))
; ;
@ -185,6 +185,7 @@ write_tail(char *s)
src_ = bank_b, dst_ = bank_a; src_ = bank_b, dst_ = bank_a;
else else
src_ = bank_a, dst_ = bank_b; src_ = bank_a, dst_ = bank_b;
if(r && !quiet) fprintf(stderr, "%02d %s\n", r->id, src_), ++r->refs;
return 1; return 1;
} }
@ -222,8 +223,7 @@ apply_rule(Rule *r, char *s)
while(*s == ' ') s++; while(*s == ' ') s++;
if(*s == ')' && *(dst_ - 1) == ' ') dst_--; if(*s == ')' && *(dst_ - 1) == ' ') dst_--;
} }
if(!quiet) fprintf(stderr, "%02d %s\n", r->id, src_), ++r->refs; return write_tail(s, r);
return write_tail(s);
} }
static char * static char *
@ -295,7 +295,7 @@ rewrite(void)
remove_rule(r); remove_rule(r);
} }
while(*cap == ' ') cap++; while(*cap == ' ') cap++;
return write_tail(cap); return write_tail(cap, NULL);
} }
/* phase: define */ /* phase: define */
if(c == '<' && s[1] == '>') { if(c == '<' && s[1] == '>') {
@ -306,7 +306,7 @@ rewrite(void)
rules_++; rules_++;
} }
while(*s == ' ') s++; while(*s == ' ') s++;
return write_tail(s); return write_tail(s, NULL);
} }
/* phase: lambda */ /* phase: lambda */
if(c == '?' && s[1] == '(') { if(c == '?' && s[1] == '(') {
@ -316,7 +316,7 @@ rewrite(void)
parse_frag(&r->b, parse_frag(&r->a, s + 2)); parse_frag(&r->b, parse_frag(&r->a, s + 2));
s = cap; s = cap;
while(*s == ' ') s++; while(*s == ' ') s++;
if(!(*r->a) || !apply_rule(r, s)) write_tail(s); if(!(*r->a) || !apply_rule(r, s)) write_tail(s, NULL);
dict_ = d; dict_ = d;
return 1; return 1;
} }

View File

@ -11,7 +11,7 @@
\n \n
) )
<> (quit listen!) (?(?: ?:) (\n\tSee you soon.\n\n)) <> (quit ...) (?(?: ?:) (\n\tSee you soon.\n\n))
<> listen?~ (?~ listen!) <> ..?~ (?~ ...)
listen! ...