zaach / jison

Bison in JavaScript.
http://jison.org
4.36k stars 450 forks source link

[feature req] support ES6/ES2016 template strings in action chunks (expand $1, etc. references in there) #359

Closed GerHobbelt closed 7 years ago

GerHobbelt commented 7 years ago

Reference: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals

Support these so we can write things like this and have those rule term references expanded properly by jison & lex-parser:

rule: a b c      
  %{ $$ = `The value is ${$a}} + ${$2} + ${$c.trim()}`; %}

should expand to something like this:

rule: a b c      
  %{ $$ = `The value is ${yyvstack[yysp - 2]} + ${yyvstack[yysp - 1]} + ${yyvstack[yysp].trim()}`; %}

after which a follow-up process MAY translate this generated parser into ES5 using babel, if such is desired, or use it as-is in ES2016 compliant environments (e.g. Node 8.0).

GerHobbelt commented 7 years ago

Working in jison-gho release 0.6.1-200