diff --git a/parse.y b/parse.y index 3469461527..c7f90d19fd 100644 --- a/parse.y +++ b/parse.y @@ -6625,7 +6625,7 @@ parser_parse_string(struct parser_params *parser, rb_strterm_literal_t *quote) static enum yytokentype parser_heredoc_identifier(struct parser_params *parser) { - int c = nextc(), term, func = 0; + int c = nextc(), term, func = 0, term_len = 2; /* length of "<<" */ enum yytokentype token = tSTRING_BEG; long len; int newline = 0; @@ -6633,24 +6633,31 @@ parser_heredoc_identifier(struct parser_params *parser) if (c == '-') { c = nextc(); + term_len++; func = STR_FUNC_INDENT; } else if (c == '~') { c = nextc(); + term_len++; func = STR_FUNC_INDENT; indent = INT_MAX; } switch (c) { case '\'': + term_len++; func |= str_squote; goto quoted; case '"': + term_len++; func |= str_dquote; goto quoted; case '`': + term_len++; token = tXSTRING_BEG; func |= str_xquote; goto quoted; quoted: + term_len++; newtok(); + tokadd(term_len); tokadd(func); term = c; while ((c = nextc()) != -1 && c != term) { @@ -6682,6 +6689,7 @@ parser_heredoc_identifier(struct parser_params *parser) return 0; } newtok(); + tokadd(term_len); tokadd(func |= str_dquote); do { if (tokadd_mbchar(c) == -1) return 0; @@ -6690,6 +6698,7 @@ parser_heredoc_identifier(struct parser_params *parser) break; } + tokenbuf[0] = tokenbuf[0] + toklen() - 2; tokfix(); dispatch_scan_event(tHEREDOC_BEG); len = lex_p - lex_pbeg; @@ -6925,7 +6934,8 @@ parser_here_document(struct parser_params *parser, rb_strterm_heredoc_t *here) rb_encoding *enc = current_enc; eos = RSTRING_PTR(here->term); - len = RSTRING_LEN(here->term) - 1; + len = RSTRING_LEN(here->term) - 2; /* here->term includes term_len and func */ + eos++; /* skip term_len */ indent = (func = *eos++) & STR_FUNC_INDENT; if ((c = nextc()) == -1) { @@ -9841,8 +9851,11 @@ rb_parser_fatal(struct parser_params *parser, const char *fmt, ...) void rb_parser_set_location_from_strterm_heredoc(struct parser_params *parser, rb_strterm_heredoc_t *here, YYLTYPE *yylloc) { + const char *eos = RSTRING_PTR(here->term); + int term_len = (int)eos[0]; + yylloc->first_loc.lineno = (int)here->sourceline; - yylloc->first_loc.column = (int)(here->u3.lastidx - RSTRING_LEN(here->term)); + yylloc->first_loc.column = (int)(here->u3.lastidx - term_len); yylloc->last_loc.lineno = (int)here->sourceline; yylloc->last_loc.column = (int)(here->u3.lastidx); }