From 135204131aebf57f04c8bbeb9746c473706ab002 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Sun, 7 Apr 2024 09:13:35 -0700 Subject: [PATCH] Added implode --- examples/test.modal | 4 ++-- src/modal.c | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) 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;