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