diff --git a/examples/test.modal b/examples/test.modal index 68b9767..01a9a30 100644 --- a/examples/test.modal +++ b/examples/test.modal @@ -1,4 +1,4 @@ -<> (plode ?*) (?*) +<> (plode (String ?*)) (String ?*) -(plode hello) +(plode (plode (String hello))) diff --git a/src/modal.c b/src/modal.c index cb52cda..7e2a69e 100644 --- a/src/modal.c +++ b/src/modal.c @@ -79,14 +79,19 @@ match(char *p, Rule *r) static char * plode(char *s) { + int i, depth = 0; char c; if(s[0] == '(') { /* implode */ - + while((c = *s++)) { + if(c == '(') depth++; + if(!spacer(c)) *outp_++ = c; + if(c == ')') --depth; + if(!depth) return s; + } } else { /* explode */ - int i, j = 0; while((c = *s++) && !spacer(c)) - *outp_++ = '(', *outp_++ = c, j++; - for(i = 0; i < j; i++) + *outp_++ = '(', *outp_++ = c, depth++; + for(i = 0; i < depth; i++) *outp_++ = ')'; } return s;