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

parser ARROW_ACTION does not detect incorrect usage #363

Open
GerHobbelt opened this issue Dec 25, 2017 · 0 comments
Open

parser ARROW_ACTION does not detect incorrect usage #363

GerHobbelt opened this issue Dec 25, 2017 · 0 comments

Comments

@GerHobbelt
Copy link
Contributor

jison has an ARROW_ACTION feature (see ebnf_parser) where you can write a grammar production with shorthand action code like this:

a
    : A                         -> 'A[' + $A + ']';
    ;

which, similar to ES6 arrow JavaScript functions, is shorthand for this jison production/action:

a
    : A                         { $$ = 'A[' + $A + ']'; }
    ;

However, the ARROW_ACTION code is a simple code injection into the generated parser, such that this code is accepted by jison:

a
    : A                         -> parser.trace('a:A');                          calc('A[' + $A + ']');
    ;

which is treated as:

a
    : A                         { $$ = parser.trace('a:A');                          calc('A[' + $A + ']'); }
    ;

which is VERY PROBABLY not as intended, resulting in unexpected behaviour.

Suggested fix direction:

Do not accept compound statements like these, but only accept a single (possibly comma-separated) JavaScript expression, e.g.:

a
    : A                         -> parser.trace('a:A'), calc('A[' + $A + ']')
    ;

so that the $$ rule's result would be assigned the value returned by calc(...) in there.

GerHobbelt added a commit to GerHobbelt/jison that referenced this issue Dec 25, 2017
…he received user-defined action code within `()` braces so that the generated parser will certainly treat the entire blurb as a single JavaScript *expression* rather than a single or compound *statement*; also note commit SHA-1: 1c8c89d :: BNF parser: produce stricter action code for arrow action in any jison grammar so that we can more easily check coding mistakes in a production's arrow code, e.g. unwanted semicolons, multiple statements, etc., which can currently slip through the net and cause hard-to-diagnose havoc down the line.

Adjusted unit tests accordingly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant