javascriptyaccjison

jison: how to add "require" in jison file?


I search online documentation but haven't found the way. For a rule like below (taken from the calculator example), I want to refer to external code.

expressions
    :  NUMBER
        {$$ = new My.Number(yytext);}

To achieve that, I need to require('My') somewhere in the jison file but when I try to add require, it is removed from the js file generated.


Solution

  • You can add another section after your grammar, like this:

    %%
    const My = require('My')