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