cancel #1565 since it breaks mirb; instead add special treatment to heredocs

parent 7e64d7e5
...@@ -113,7 +113,6 @@ struct mrb_parser_state { ...@@ -113,7 +113,6 @@ struct mrb_parser_state {
char const *filename; char const *filename;
int lineno; int lineno;
int column; int column;
int eof;
enum mrb_lex_state_enum lstate; enum mrb_lex_state_enum lstate;
mrb_ast_node *lex_strterm; /* (type nest_level beg . end) */ mrb_ast_node *lex_strterm; /* (type nest_level beg . end) */
......
...@@ -3333,19 +3333,13 @@ nextc(parser_state *p) ...@@ -3333,19 +3333,13 @@ nextc(parser_state *p)
return c; return c;
eof: eof:
if (!p->eof) {
p->eof = TRUE;
return '\n';
}
if (!p->cxt) return -1; if (!p->cxt) return -1;
else { else {
mrbc_context *cxt = p->cxt; mrbc_context *cxt = p->cxt;
if (cxt->partial_hook(p) < 0) return -1; if (cxt->partial_hook(p) < 0) return -1;
p->eof = FALSE; c = '\n';
p->cxt = NULL; p->lineno = 1;
c = nextc(p);
p->cxt = cxt; p->cxt = cxt;
return c; return c;
} }
...@@ -3873,6 +3867,9 @@ heredoc_identifier(parser_state *p) ...@@ -3873,6 +3867,9 @@ heredoc_identifier(parser_state *p)
return 0; return 0;
} }
} else { } else {
if (c == -1) {
return 0; /* missing here document identifier */
}
if (! identchar(c)) { if (! identchar(c)) {
pushback(p, c); pushback(p, c);
if (indent) pushback(p, '-'); if (indent) pushback(p, '-');
...@@ -3936,7 +3933,10 @@ parser_yylex(parser_state *p) ...@@ -3936,7 +3933,10 @@ parser_yylex(parser_state *p)
case '\0': /* NUL */ case '\0': /* NUL */
case '\004': /* ^D */ case '\004': /* ^D */
case '\032': /* ^Z */ case '\032': /* ^Z */
return 0;
case -1: /* end of script. */ case -1: /* end of script. */
if (p->heredocs_from_nextline)
goto maybe_heredoc;
return 0; return 0;
/* white spaces */ /* white spaces */
...@@ -3949,6 +3949,7 @@ parser_yylex(parser_state *p) ...@@ -3949,6 +3949,7 @@ parser_yylex(parser_state *p)
skip(p, '\n'); skip(p, '\n');
/* fall through */ /* fall through */
case '\n': case '\n':
maybe_heredoc:
heredoc_treat_nextline(p); heredoc_treat_nextline(p);
switch (p->lstate) { switch (p->lstate) {
case EXPR_BEG: case EXPR_BEG:
......
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