ruby-changes:48919
From: yui-knk <ko1@a...>
Date: Wed, 6 Dec 2017 09:44:27 +0900 (JST)
Subject: [ruby-changes:48919] yui-knk:r61037 (trunk): parse.y: Fix locations of HEREDOC
yui-knk 2017-12-06 09:44:18 +0900 (Wed, 06 Dec 2017) New Revision: 61037 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61037 Log: 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)) ``` Modified files: trunk/parse.y Index: parse.y =================================================================== --- parse.y (revision 61036) +++ parse.y (revision 61037) @@ -62,6 +62,8 @@ https://github.com/ruby/ruby/blob/trunk/parse.y#L62 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 p https://github.com/ruby/ruby/blob/trunk/parse.y#L681 #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_sta https://github.com/ruby/ruby/blob/trunk/parse.y#L691 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, st https://github.com/ruby/ruby/blob/trunk/parse.y#L8867 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 *pa https://github.com/ruby/ruby/blob/trunk/parse.y#L9839 } 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; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/