diff --git a/src/modal.c b/src/modal.c index e799db9..ec16280 100644 --- a/src/modal.c +++ b/src/modal.c @@ -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; diff --git a/test.modal b/test.modal index 9a0ea5c..67aba8c 100644 --- a/test.modal +++ b/test.modal @@ -1,3 +1,3 @@ -<> bar baz +<> (?x dup) (?x ?x) -foo bar \ No newline at end of file +foo (hey dup) \ No newline at end of file