ruby-changes:51417
From: yui-knk <ko1@a...>
Date: Sun, 10 Jun 2018 15:22:20 +0900 (JST)
Subject: [ruby-changes:51417] yui-knk:r63623 (trunk): parse.y: Fix locations of none and mid-rule actions
yui-knk 2018-06-10 15:22:15 +0900 (Sun, 10 Jun 2018) New Revision: 63623 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63623 Log: parse.y: Fix locations of none and mid-rule actions When an empty rule or a mid-rule action is reduced, `YYLLOC_DEFAULT` is called with the third parameter to be zero. If we use `RUBY_SET_YYLLOC_OF_NONE` to set their locations, sometimes the end position of NODE indicates a blank. For example, `a.b ;` generates `NODE_CALL (line: 1, location: (1,0)-(1,4))*`, whose end position indicates a blank. This is because of the following reasons: * `NODE_CALL` is created when `primary_value call_op operation2 opt_paren_args` is reduced to `method_call`. * `opt_paren_args` is `none`. * `yylex` is called and `lex.pbeg` moves before `none` is reduced, so the beginning position of `none` does not match with the end position of `operation2`. To fix locations, use `YYRHSLOC(Rhs, 0)` in `YYLLOC_DEFAULT` (0 "refers to the symbol just before the reduction"). By this change, the bottom of the location stack would be referenced, so initialize the bottom with `RUBY_SET_YYLLOC_OF_NONE` in `%initial-action`. Ref: https://www.gnu.org/software/bison/manual/html_node/Location-Default-Action.html#Location-Default-Action Modified files: trunk/parse.y Index: parse.y =================================================================== --- parse.y (revision 63622) +++ parse.y (revision 63623) @@ -59,7 +59,10 @@ https://github.com/ruby/ruby/blob/trunk/parse.y#L59 (Current).end_pos = YYRHSLOC(Rhs, N).end_pos; \ } \ else \ - RUBY_SET_YYLLOC_OF_NONE(Current); \ + { \ + (Current).beg_pos = YYRHSLOC(Rhs, 0).end_pos; \ + (Current).end_pos = YYRHSLOC(Rhs, 0).end_pos; \ + } \ while (0) #define RUBY_SET_YYLLOC_FROM_STRTERM_HEREDOC(Current) \ @@ -747,6 +750,10 @@ static void token_info_warn(struct parse https://github.com/ruby/ruby/blob/trunk/parse.y#L750 %pure-parser %lex-param {struct parser_params *p} %parse-param {struct parser_params *p} +%initial-action +{ + RUBY_SET_YYLLOC_OF_NONE(@$); +}; %union { VALUE val; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/