[ruby-cvs:70714] yui-knk:r63623 (trunk): parse.y: Fix locations of none and mid-rule actions

yui-knk at ruby-lang.org yui-knk at ruby-lang.org
Sun Jun 10 15:22:16 JST 2018

yui-knk	2018-06-10 15:22:15 +0900 (Sun, 10 Jun 2018)

  New Revision: 63623


    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:

More information about the ruby-cvs mailing list