Open mluis opened 6 years ago
@mluis jison currently only supports commonjs/amd module or global variable. listed here https://github.com/zaach/jison#usage-from-the-command-line. Unfortunately it doesn't support es6 module and if you want it the es6 way, you can write a small script to append one line
export default <parserName>;
at the bottom of file.
so that you can do import Parser from 'path-to-generated-parser-file'
in your angular code.
When trying to import either a generated parser or jison itself in an Angular 7 project I get errors about the lack of node modules fs and path:
Module not found: Error: Can't resolve 'fs' Module not found: Error: Can't resolve 'path'
I can get the generated parser to work by removing the two lines referencing fs and path, but there must be a better way, especially so that one could use the jison npm package.
You can use the option moduleType
as follows:
parser.generate({ moduleName: 'moduleName', moduleType: 'js' })
It will generate the parser without those lines. Be careful with the lexer —if you are using a custom one— and custom functionality that you pass through the 'yy' object.
generateModule
so it can generate the rules on the output parser. If it doesn't, it won't work. yy: {}
, so you'll need to add it manually.
After a successful generated parser one might not need jison to be included in a project for parsers generation. My question is how to include the generated parser in a project like angular, for example ?
BR