New explode/join registers

This commit is contained in:
Devine Lu Linvega 2024-04-17 10:35:40 -07:00
parent 3bce3dab79
commit 6e0d3bb9e0
1 changed files with 20 additions and 24 deletions

View File

@ -55,32 +55,31 @@ put_reg(char r)
} }
ss = walk(s); ss = walk(s);
if(r == '*') { if(r == '*') {
if(*s == '(') { /* special implode */
while(s < ss && (c = *s++))
if(!spacer(c)) *dst_++ = c;
} else { /* special explode */
int i, depth = 0;
while((c = *s++) && !spacer(c))
*dst_++ = c, *dst_++ = ' ', *dst_++ = '(', depth++;
for(i = 0; i < depth; i++)
*dst_++ = ')';
}
} else if(r == '.') { /* special unpack */
if(*s == '(')
s++, --ss;
while(s < ss) *dst_++ = *s++;
} else if(r == '^') { /* special align */
int i, depth = 0; int i, depth = 0;
if(*s == '(') { /* special explode tuple */
s++; s++;
while(s < ss) { while(s < ss) {
*dst_++ = '(';
while((c = *s) && !spacer(c)) while((c = *s) && !spacer(c))
*dst_++ = c, s++; *dst_++ = c, s++;
if(s < ss - 1) *dst_++ = ' '; *dst_++ = ' ';
s++, depth++; *dst_++ = '(', s++, depth++;
}
} else { /* special explode token */
while((c = *s++) && !spacer(c))
*dst_++ = c, *dst_++ = ' ', *dst_++ = '(', depth++;
} }
for(i = 0; i < depth; i++) for(i = 0; i < depth; i++)
*dst_++ = ')'; *dst_++ = ')';
} else if(r == '.') { /* special unpack */
if(*s == '(') s++, --ss;
while(s < ss) *dst_++ = *s++;
} else if(r == '^') { /* special join */
if(*s == '(') s++, --ss;
while(s < ss && (c = *s++))
if(!spacer(c)) *dst_++ = c;
} else if(r == '~') { /* special stdin */
while(fread(&c, 1, 1, stdin) && c >= ' ')
*dst_++ = c;
} else if(r == ':') { /* special stdout */ } else if(r == ':') { /* special stdout */
if(*s == '(') s++, --ss; if(*s == '(') s++, --ss;
while(s < ss) { while(s < ss) {
@ -94,9 +93,6 @@ put_reg(char r)
} else } else
putc(c, stdout); putc(c, stdout);
} }
} else if(r == '~') { /* special stdin */
while(fread(&c, 1, 1, stdin) && c >= ' ')
*dst_++ = c;
} else } else
while(s < ss) *dst_++ = *s++; while(s < ss) *dst_++ = *s++;
} }