summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authoryui-knk <yui-knk@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-06 00:44:18 +0000
committeryui-knk <yui-knk@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-06 00:44:18 +0000
commitf7899d3c80e5e234240c3e549579a0185f99007f (patch)
tree8de56561feda56af822179528316bcaa80f0b66d /parse.y
parentb034a9d226cb76afab3798ef7f6a4c825fd5146a (diff)
parse.y: Fix locations of HEREDOC
* parse.y (rb_parser_set_location_from_strterm_heredoc): Set locations based on rb_strterm_heredoc_t. * parse.y (yylex): Set yylloc based on rb_strterm_heredoc_t when parsing heredoc. e.g. The locations of the NODE_DSTR is changed: ``` a <<STR 123 #{:a} STR ``` * Before ``` NODE_DSTR (line: 3, code_range: (3,0)-(1,7)) ``` * After ``` NODE_DSTR (line: 3, code_range: (1,3)-(1,7)) ``` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y20
1 files changed, 19 insertions, 1 deletions
diff --git a/parse.y b/parse.y
index 120dab0e54..2c0babcb8b 100644
--- a/parse.y
+++ b/parse.y
@@ -62,6 +62,8 @@
RUBY_SET_YYLLOC(Current); \
while (0)
+#define RUBY_SET_YYLLOC_FROM_STRTERM_HEREDOC(Current) \
+ rb_parser_set_location_from_strterm_heredoc(parser, &lex_strterm->u.heredoc, &(Current))
#define RUBY_SET_YYLLOC(Current) \
rb_parser_set_location(parser, &(Current))
@@ -679,6 +681,9 @@ static VALUE parser_reg_compile(struct parser_params*, VALUE, int, VALUE *);
#endif /* !RIPPER */
+/* forward declaration */
+typedef struct rb_strterm_heredoc_struct rb_strterm_heredoc_t;
+
RUBY_SYMBOL_EXPORT_BEGIN
VALUE rb_parser_reg_compile(struct parser_params* parser, VALUE str, int options);
int rb_reg_fragment_setenc(struct parser_params*, VALUE, int);
@@ -686,6 +691,7 @@ enum lex_state_e rb_parser_trace_lex_state(struct parser_params *, enum lex_stat
VALUE rb_parser_lex_state_name(enum lex_state_e state);
void rb_parser_show_bitstack(struct parser_params *, stack_type, const char *, int);
PRINTF_ARGS(void rb_parser_fatal(struct parser_params *parser, const char *fmt, ...), 2, 3);
+void rb_parser_set_location_from_strterm_heredoc(struct parser_params *parser, rb_strterm_heredoc_t *here, YYLTYPE *yylloc);
void rb_parser_set_location(struct parser_params *parser, YYLTYPE *yylloc);
RUBY_SYMBOL_EXPORT_END
@@ -8861,7 +8867,10 @@ yylex(YYSTYPE *lval, YYLTYPE *yylloc, struct parser_params *parser)
else if (t != 0)
dispatch_scan_event(t);
- RUBY_SET_YYLLOC(*yylloc);
+ if (lex_strterm && (lex_strterm->flags & STRTERM_HEREDOC))
+ RUBY_SET_YYLLOC_FROM_STRTERM_HEREDOC(*yylloc);
+ else
+ RUBY_SET_YYLLOC(*yylloc);
return t;
}
@@ -9830,6 +9839,15 @@ 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)
+{
+ yylloc->first_loc.lineno = (int)here->sourceline;
+ yylloc->first_loc.column = (int)(here->u3.lastidx - RSTRING_LEN(here->term));
+ yylloc->last_loc.lineno = (int)here->sourceline;
+ yylloc->last_loc.column = (int)(here->u3.lastidx);
+}
+
+void
rb_parser_set_location(struct parser_params *parser, YYLTYPE *yylloc)
{
yylloc->first_loc.lineno = ruby_sourceline;