From 920be34b20db3de3d2d60d1f0bec80cbb1ad7410 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Thu, 4 Apr 2024 19:48:10 -0700 Subject: [PATCH] Fixed issue in write reg --- examples/test.modal | 6 +++--- src/modal.c | 24 +++++++++++------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/examples/test.modal b/examples/test.modal index c9e0aa4..dd63d61 100644 --- a/examples/test.modal +++ b/examples/test.modal @@ -1,4 +1,4 @@ -<> (swap ?x ?y) (?y ?x) - -(swap (123) (456)) +<> (?x dup) (?x ?x) +<> (?x ?y swap) (?y ?x) +foo ((A B swap) dup) \ No newline at end of file diff --git a/src/modal.c b/src/modal.c index ed261dd..61431c0 100644 --- a/src/modal.c +++ b/src/modal.c @@ -35,31 +35,29 @@ match(char *p, Rule *r) { char c, *a = r->a, *b = p; while((c = *a)) { - if(c == '?') { - regs[(int)*(++a)] = b, a++, b = walk(b), c = *b; - } + if(c == '?') regs[(int)*(++a)] = b, a++, b = walk(b), c = *b; if(c != *b) return NULL; a++, b++; } return b; } -static int +static void writereg(char r) { int depth = 0; char c, *s = regs[(int)r]; - while((c = *s++)) { - if(c == '(') depth++; - if(c == ')') { - --depth; - if(!depth) break; + if(s[0] == '(') { + while((c = *s++)) { + if(c == '(') depth++; + *outp_++ = c; + if(c == ')') --depth; + if(!depth) return; } - if(depth < 0) break; - if(depth == 0 && c == ' ') break; - *outp_++ = c; } - return 1; + while(!spacer(s[0]) && (*outp_++ = *s++)) + ; + return; } static void