Commit ec0a94da authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #1565 from Fleurer/fix1564

nextc(): always return an '\n' at end of input
parents f80401de fa71403b
......@@ -113,6 +113,7 @@ struct mrb_parser_state {
char const *filename;
int lineno;
int column;
int eof;
enum mrb_lex_state_enum lstate;
mrb_ast_node *lex_strterm; /* (type nest_level beg . end) */
......
......@@ -3316,14 +3316,14 @@ nextc(parser_state *p)
else {
#ifdef ENABLE_STDIO
if (p->f) {
if (feof(p->f)) goto end_retry;
if (feof(p->f)) goto eof;
c = fgetc(p->f);
if (c == EOF) goto end_retry;
if (c == EOF) goto eof;
}
else
#endif
if (!p->s || p->s >= p->send) {
goto end_retry;
goto eof;
}
else {
c = (unsigned char)*p->s++;
......@@ -3332,14 +3332,20 @@ nextc(parser_state *p)
p->column++;
return c;
end_retry:
eof:
if (!p->eof) {
p->eof = TRUE;
return '\n';
}
if (!p->cxt) return -1;
else {
mrbc_context *cxt = p->cxt;
if (cxt->partial_hook(p) < 0) return -1;
c = '\n';
p->lineno = 1;
p->eof = FALSE;
p->cxt = NULL;
c = nextc(p);
p->cxt = cxt;
return c;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment