Added implode
This commit is contained in:
parent
2831040581
commit
135204131a
|
@ -1,4 +1,4 @@
|
|||
<> (plode ?*) (?*)
|
||||
<> (plode (String ?*)) (String ?*)
|
||||
|
||||
(plode hello)
|
||||
(plode (plode (String hello)))
|
||||
|
||||
|
|
13
src/modal.c
13
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;
|
||||
|
|
Loading…
Reference in New Issue