Write EOF token via ?~ register
This commit is contained in:
parent
88b5c527f4
commit
47b80e126e
|
@ -1,5 +1,6 @@
|
|||
?(?-) (This is a fully functional Modal REPL.)
|
||||
|
||||
<> (EOF wait stdin) ((Bye.\n) print)
|
||||
<> (quit wait stdin) ((You quit.\n) print)
|
||||
<> (?: print) (?:)
|
||||
<> (wait ?~) (?~ wait stdin)
|
||||
|
|
19
src/modal.c
19
src/modal.c
|
@ -29,7 +29,7 @@ walk(char *s)
|
|||
return s;
|
||||
}
|
||||
|
||||
static int
|
||||
static void
|
||||
write_reg(char r, char *reg)
|
||||
{
|
||||
char c, *cap = walk(reg);
|
||||
|
@ -47,20 +47,23 @@ write_reg(char r, char *reg)
|
|||
} else
|
||||
putc(c, stdout);
|
||||
}
|
||||
return 0;
|
||||
case '~': /* op: input */
|
||||
return;
|
||||
case '~': { /* op: input */
|
||||
while(fread(&c, 1, 1, stdin) && c >= ' ')
|
||||
*dst_++ = c;
|
||||
return 1;
|
||||
if(feof(stdin))
|
||||
*dst_++ = 'E', *dst_++ = 'O', *dst_++ = 'F';
|
||||
return;
|
||||
}
|
||||
case '^': /* op: join */
|
||||
if(*reg == '(') reg++, --cap;
|
||||
while(reg < cap && (c = *reg++))
|
||||
if(!spacer(c)) *dst_++ = c;
|
||||
return 1;
|
||||
return;
|
||||
case '.': /* op: unwrap */
|
||||
if(*reg == '(') reg++, --cap;
|
||||
while(reg < cap) *dst_++ = *reg++;
|
||||
return 1;
|
||||
return;
|
||||
case '*': { /* op: explode */
|
||||
int i, depth = 0;
|
||||
if(*reg == '(' && reg[1] != ')') { /* tuple */
|
||||
|
@ -75,11 +78,11 @@ write_reg(char r, char *reg)
|
|||
while((c = *reg++) && !spacer(c))
|
||||
*dst_++ = c, *dst_++ = ' ', *dst_++ = '(', depth++;
|
||||
for(i = 0; i < depth; i++) *dst_++ = ')';
|
||||
return 1;
|
||||
return;
|
||||
}
|
||||
default:
|
||||
while(reg < cap) *dst_++ = *reg++;
|
||||
return 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue