diff options
| author | fleuria <[email protected]> | 2013-11-08 11:36:45 +0800 |
|---|---|---|
| committer | fleuria <[email protected]> | 2013-11-08 11:40:26 +0800 |
| commit | fa71403bc5578cff9dfa8a9de36026bd9b6b0220 (patch) | |
| tree | 43529fd1c513b511a780f83d5d0da3b1462d8c3a | |
| parent | d2451dfb1660c219e7ba7bc2ae4ee859040b8d84 (diff) | |
| download | mruby-fa71403bc5578cff9dfa8a9de36026bd9b6b0220.tar.gz mruby-fa71403bc5578cff9dfa8a9de36026bd9b6b0220.zip | |
nextc(): always return an '\n' at end of input
fix #1564
| -rw-r--r-- | include/mruby/compile.h | 1 | ||||
| -rw-r--r-- | src/parse.y | 18 |
2 files changed, 13 insertions, 6 deletions
diff --git a/include/mruby/compile.h b/include/mruby/compile.h index 36cb67186..a75694f55 100644 --- a/include/mruby/compile.h +++ b/include/mruby/compile.h @@ -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) */ diff --git a/src/parse.y b/src/parse.y index 12dcfa471..c382c633c 100644 --- a/src/parse.y +++ b/src/parse.y @@ -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; } |
