Open GerHobbelt opened 6 years ago
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.
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.
$$
calc(...)
jison has an ARROW_ACTION feature (see ebnf_parser) where you can write a grammar production with shorthand action code like this:
which, similar to ES6 arrow JavaScript functions, is shorthand for this jison production/action:
However, the ARROW_ACTION code is a simple code injection into the generated parser, such that this code is accepted by jison:
which is treated as:
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.:
so that the
$$
rule's result would be assigned the value returned bycalc(...)
in there.