diff options
author | yui-knk <yui-knk@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-06 03:09:55 +0000 |
---|---|---|
committer | yui-knk <yui-knk@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-06 03:09:55 +0000 |
commit | c1bd83cef742b7ff68d02cc490d018c6ac4d8c13 (patch) | |
tree | e9261f1b2ecc8ebe2b9a7c1ff7b287202a0fd95a /parse.y | |
parent | b7c17ad14d98e568e99811566d0d5989c9a83f2c (diff) |
parse.y: Fix the first location of heredoc identifier
* parse.y (parser_heredoc_identifier):
Put length of term at the head of rb_strterm_heredoc_struct.term.
* parse.y (rb_parser_set_location_from_strterm_heredoc):
Use length of term to calculate first_loc.column.
e.g. The locations of the NODE_DSTR is fixed:
```
a <<STR
123
#{:a}
STR
```
* Before
```
NODE_DSTR (line: 3, code_range: (1,3)-(1,7))
```
* After
```
NODE_DSTR (line: 3, code_range: (1,2)-(1,7))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r-- | parse.y | 19 |
1 files changed, 16 insertions, 3 deletions
@@ -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); } |