accept empty lines in repl
This commit is contained in:
parent
d6c377a33b
commit
223e873ff0
|
@ -71,6 +71,12 @@ typedef struct {
|
|||
|
||||
typedef pic_value (*pic_func_t)(pic_state *);
|
||||
|
||||
enum pic_parser_res {
|
||||
PIC_PARSER_INCOMPLETE = -1,
|
||||
PIC_PARSER_ERROR = -2
|
||||
/* if parser is successfully done, return the number of exprs (>= 0) */
|
||||
};
|
||||
|
||||
void *pic_alloc(pic_state *, size_t);
|
||||
void *pic_realloc(pic_state *, void *, size_t);
|
||||
void *pic_calloc(pic_state *, unsigned, size_t);
|
||||
|
|
|
@ -33,7 +33,7 @@ pic_load_stdlib(pic_state *pic)
|
|||
}
|
||||
|
||||
n = pic_parse_file(pic, file, &vs);
|
||||
if (n <= 0) {
|
||||
if (n < 0) {
|
||||
fputs("fatal error: built-in.scm broken", stderr);
|
||||
abort();
|
||||
}
|
||||
|
|
14
src/parse.y
14
src/parse.y
|
@ -67,6 +67,10 @@ program
|
|||
p->incomp = true;
|
||||
p->value = pic_undef_value();
|
||||
}
|
||||
| /* empty line */
|
||||
{
|
||||
p->value = pic_nil_value();
|
||||
}
|
||||
;
|
||||
|
||||
program_data
|
||||
|
@ -249,17 +253,17 @@ pic_parse_file(pic_state *pic, FILE *file, pic_value *v)
|
|||
|
||||
if (p.yynerrs > 0) {
|
||||
p.value = pic_undef_value();
|
||||
return -1;
|
||||
return PIC_PARSER_ERROR;
|
||||
}
|
||||
if (p.incomp) {
|
||||
return 0;
|
||||
return PIC_PARSER_INCOMPLETE;
|
||||
}
|
||||
|
||||
*v = p.value;
|
||||
return pic_length(pic, p.value);
|
||||
}
|
||||
|
||||
int
|
||||
enum pic_parser_res
|
||||
pic_parse_cstr(pic_state *pic, const char *str, pic_value *v)
|
||||
{
|
||||
struct parser_control p;
|
||||
|
@ -274,10 +278,10 @@ pic_parse_cstr(pic_state *pic, const char *str, pic_value *v)
|
|||
yylex_destroy(p.yyscanner);
|
||||
|
||||
if (p.yynerrs > 0) {
|
||||
return -1;
|
||||
return PIC_PARSER_ERROR;
|
||||
}
|
||||
if (p.incomp) {
|
||||
return 0;
|
||||
return PIC_PARSER_INCOMPLETE;
|
||||
}
|
||||
|
||||
*v = p.value;
|
||||
|
|
|
@ -103,11 +103,11 @@ repl(pic_state *pic)
|
|||
|
||||
/* read */
|
||||
n = pic_parse_cstr(pic, code, &vs);
|
||||
if (n == 0) { /* wait for more input */
|
||||
if (n == PIC_PARSER_INCOMPLETE) { /* wait for more input */
|
||||
goto next;
|
||||
}
|
||||
code[0] = '\0';
|
||||
if (n == -1) { /* parse error */
|
||||
if (n == PIC_PARSER_ERROR) { /* parse error */
|
||||
goto next;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue