简体   繁体   中英

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.

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

%%
const My = require('My') 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM