Skip to content

proposal: x/tools/cmd/goyacc: reduce dependence on globals #44774

@SteelPhase

Description

@SteelPhase

background

Code generated by goyacc has a dependence on package globals that it doesn't need to have.

yyDebug, and yyErrorVerbose do not specifically need to be globals, and can be variables on the parser instead.

I did not find documentation for bison/yacc that states YYDEBUG or a YYERRORVERBOSE need to be made available inside grammar actions.

We can follow java here and expose them via the Parser which is already technically available to grammar actions but not documented.

description

I'm proposing the following

  • Move yyDebug, and yyErrorVerbose into yyParserImpl
  • For compatibility, modify yyNewParser to grab the value of the package globals, and set them internally when called
    • something like `return &$$ParserImpl{ debug: $$Debug, errorVerbose: $$ErrorVerbose}
  • Create a new yyNewParser### function that exposed debug, and errorVerbose as inputs
  • Create a new yyParse### function that exposed debug, and errorVerbose as inputs
  • Modify the yyParser interface to expose, and allow modification of, the internal state of debug, and errorVerbose
  • Modify yyParserImpl to match the updated yyParser interface

drawbacks

There is potential that if someone had already written a customer parser to match yyParser their parser would no longer match the interface

Any grammar actions that depend on yyDebug or yyErrorVerbose would break. A key point here is this behavior doesn't seem to be well defined
anyways, and I'm not sure if the intention was to make them available in grammar actions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions