From 91b68104d09ac7bb42a40887e6cf522491baca7d Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Thu, 4 Apr 2024 12:20:06 -0700 Subject: [PATCH] Writing registers --- src/modal.c | 20 +++++++++++++++++++- test.modal | 4 ++-- 2 files changed, 21 insertions(+), 3 deletions(-) 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