Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

action code in grammar doesn't expand @label ref inside template string with comments #30

Open
GerHobbelt opened this issue Nov 9, 2017 · 0 comments
Milestone

Comments

@GerHobbelt
Copy link
Owner

Offending bnf.y grammar excerpt where @action after the @0 IS NOT expanded into proper JavaScript code like it should:

handle_action
    : handle prec action
        {
            $$ = [($handle.length ? $handle.join(' ') : '')];
            if ($action) {
                var rv = checkActionBlock($action, @action);
                if (rv) {
                    yyerror(rmCommonWS`
                        production rule action code block does not compile: ${rv}

                          Erroneous area:
                        ${yylexer.prettyPrintRange(@action, @handle)}
                    `);
                }
                $$.push($action);
            }
            if ($prec) {
                if ($handle.length === 0) {
                    yyerror(rmCommonWS`
                        You cannot specify a precedence override for an epsilon (a.k.a. empty) rule!

                          Erroneous area:
                        ${yylexer.prettyPrintRange(@handle, @0 /* @handle is very probably NULL! We need this one for some decent location info! */, @action /* ditto! */)}
                    `);
                }
                $$.push($prec);
            }
            if ($$.length === 1) {
                $$ = $$[0];
            }
        }

Removing the comment immediately following @0 fixes the problem.

This must be a problem with my code rewriter logic in there; it's still regex-based and apparently goes bonkers when you mix comments with ES6 string templates. Grmbl. I was planning to migrate to using recast AST rewriting already, but that will take some effort / time that is in short supply. :-(

GerHobbelt added a commit to GerHobbelt/esprima that referenced this issue Nov 10, 2017
 (which currently still uses regexes for code manipulation instead of esprima+recast AST rewriting) :: action code in grammar doesn't expand `@label` ref inside template string with comments
@GerHobbelt GerHobbelt added this to the 0.6.5 milestone May 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant