summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/parse.y20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/parse.y b/src/parse.y
index 27c2dd80d..9841351ea 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -3373,7 +3373,9 @@ nextc(parser_state *p)
c = (unsigned char)*p->s++;
}
}
- p->column++;
+ if (c >= 0) {
+ p->column++;
+ }
if (c == '\r') {
c = nextc(p);
if (c != '\n') {
@@ -3388,16 +3390,17 @@ nextc(parser_state *p)
if (!p->cxt) return -1;
else {
if (p->cxt->partial_hook(p) < 0)
- return -1;
- return '\n';
+ return -1; /* end of program(s) */
+ return -2; /* end of a file in the program files */
}
}
static void
pushback(parser_state *p, int c)
{
- if (c < 0) return;
- p->column--;
+ if (c >= 0) {
+ p->column--;
+ }
p->pb = cons((node*)(intptr_t)c, p->pb);
}
@@ -3421,7 +3424,7 @@ peekc_n(parser_state *p, int n)
do {
c0 = nextc(p);
- if (c0 < 0) return c0;
+ if (c0 == -1) return c0; /* do not skip partial EOF */
list = push(list, (node*)(intptr_t)c0);
} while(n--);
if (p->pb) {
@@ -3777,6 +3780,7 @@ read_escape(parser_state *p)
eof:
case -1:
+ case -2: /* end of a file */
yyerror(p, "Invalid escape character syntax");
return '\0';
@@ -4092,6 +4096,7 @@ parser_yylex(parser_state *p)
case '#': /* it's a comment */
skip(p, '\n');
/* fall through */
+ case -2: /* end of a file */
case '\n':
maybe_heredoc:
heredoc_treat_nextline(p);
@@ -4126,6 +4131,7 @@ parser_yylex(parser_state *p)
goto retry;
}
case -1: /* EOF */
+ case -2: /* end of a file */
goto normal_newline;
default:
pushback(p, c);
@@ -5447,7 +5453,7 @@ mrb_parser_set_filename(struct mrb_parser_state *p, const char *f)
sym = mrb_intern_cstr(p->mrb, f);
p->filename = mrb_sym2name_len(p->mrb, sym, NULL);
- p->lineno = (p->filename_table_length > 0)? -1 : 1;
+ p->lineno = (p->filename_table_length > 0)? 0 : 1;
for (i = 0; i < p->filename_table_length; ++i) {
if (p->filename_table[i] == sym) {