diff --git a/examples/test.modal b/examples/test.modal index 2b3e220..68b9767 100644 --- a/examples/test.modal +++ b/examples/test.modal @@ -1,5 +1,4 @@ -<> (?x dup) (?x ?x) -<> (?x ?y swap) (?y ?x) -<> ( ?x pop) () +<> (plode ?*) (?*) + +(plode hello) -(1 2 3) (4 5 6) swap pop dup diff --git a/src/modal.c b/src/modal.c index 0499d19..cb52cda 100644 --- a/src/modal.c +++ b/src/modal.c @@ -76,14 +76,32 @@ match(char *p, Rule *r) return spacer(*b) ? b : NULL; } +static char * +plode(char *s) +{ + char c; + if(s[0] == '(') { /* implode */ + + } else { /* explode */ + int i, j = 0; + while((c = *s++) && !spacer(c)) + *outp_++ = '(', *outp_++ = c, j++; + for(i = 0; i < j; i++) + *outp_++ = ')'; + } + return s; +} + static int -bind(char r, char *incoming) +commit(char r, char *incoming) { int depth = 0; char c, *s = regs[(int)r]; if(r == ':' && incoming != NULL) s = incoming, queue++; if(!s) return !fprintf(stderr, "?%c Empty\n", r); - if(s[0] == '(') { + if(r == '*') + s = plode(s); + else if(s[0] == '(') { while((c = *s++)) { if(c == '(') depth++; *outp_++ = c; @@ -161,7 +179,7 @@ rewrite(char *incoming) char cc, *b = r->b; while((cc = *b++)) { if(cc == '?') - bind(*b++, incoming); + commit(*b++, incoming); else *outp_++ = cc; }