Writing registers

This commit is contained in:
Devine Lu Linvega 2024-04-04 12:20:06 -07:00
parent 36cf4b295f
commit 91b68104d0
2 changed files with 21 additions and 3 deletions

View File

@ -37,6 +37,21 @@ match(char *p, Rule *r)
return b;
}
static int
writereg(char r)
{
int depth = 0;
char c, *s = regs[(int)r];
while((c = *s++)) {
if(c == '(') depth++;
if(c == ')') --depth;
if(c == ' ' && !depth)
break;
*outp_++ = c;
}
return 1;
}
static int
rewrite(void)
{
@ -49,7 +64,10 @@ rewrite(void)
if(res != NULL) {
char cc, *b = r->b;
while((cc = *b++)) {
*outp_++ = cc;
if(cc == '?')
writereg(*b++);
else
*outp_++ = cc;
}
found = 1;
p = res;

View File

@ -1,3 +1,3 @@
<> bar baz
<> (?x dup) (?x ?x)
foo bar
foo (hey dup)