From 47f5f887e892ce46fecd12ad97193a501e09accb Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Thu, 7 May 2020 08:36:36 +0900 Subject: Fix wrong line number before comment line; fix #4993 --- mrbgems/mruby-compiler/core/parse.y | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y index 7ca2e088f..0a016e23f 100644 --- a/mrbgems/mruby-compiler/core/parse.y +++ b/mrbgems/mruby-compiler/core/parse.y @@ -3856,7 +3856,7 @@ term : ';' {yyerrok;} nl : '\n' { - p->lineno++; + p->lineno += $1; p->column = 0; } ; @@ -4844,6 +4844,7 @@ static int parser_yylex(parser_state *p) { int32_t c; + int nlines = 1; int space_seen = 0; int cmd_state; enum mrb_lex_state_enum last_state; @@ -4901,6 +4902,7 @@ parser_yylex(parser_state *p) break; } if (p->parsing_heredoc != NULL) { + pylval.num = nlines; return '\n'; } while ((c = nextc(p))) { @@ -4910,13 +4912,13 @@ parser_yylex(parser_state *p) space_seen = 1; break; case '#': /* comment as a whitespace */ - pushback(p, '#'); - p->lineno++; - goto retry; + skip(p, '\n'); + nlines++; + break; case '.': if (!peek(p, '.')) { pushback(p, '.'); - p->lineno++; + p->lineno+=nlines; nlines=1; goto retry; } pushback(p, c); @@ -4924,7 +4926,7 @@ parser_yylex(parser_state *p) case '&': if (peek(p, '.')) { pushback(p, '&'); - p->lineno++; + p->lineno+=nlines; nlines=1; goto retry; } pushback(p, c); @@ -4940,6 +4942,7 @@ parser_yylex(parser_state *p) normal_newline: p->cmd_start = TRUE; p->lstate = EXPR_BEG; + pylval.num = nlines; return '\n'; case '*': @@ -5022,7 +5025,7 @@ parser_yylex(parser_state *p) c = nextc(p); } while (!(c < 0 || ISSPACE(c))); if (c != '\n') skip(p, '\n'); - p->lineno++; + p->lineno+=nlines; nlines=1; p->column = 0; goto retry; } @@ -5744,7 +5747,7 @@ parser_yylex(parser_state *p) case '\\': c = nextc(p); if (c == '\n') { - p->lineno++; + p->lineno+=nlines; nlines=1; p->column = 0; space_seen = 1; goto retry; /* skip \\n */ -- cgit v1.2.3