Added implode

This commit is contained in:
Devine Lu Linvega 2024-04-07 09:13:35 -07:00
parent 2831040581
commit 135204131a
2 changed files with 11 additions and 6 deletions

View File

@ -1,4 +1,4 @@
<> (plode ?*) (?*)
<> (plode (String ?*)) (String ?*)
(plode hello)
(plode (plode (String hello)))

View File

@ -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;