Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to include parser in angular project #382

Open
mluis opened this issue Nov 22, 2018 · 3 comments
Open

How to include parser in angular project #382

mluis opened this issue Nov 22, 2018 · 3 comments

Comments

@mluis
Copy link

mluis commented Nov 22, 2018

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

@liqiang372
Copy link

@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.

@drewwiens
Copy link

drewwiens commented Mar 1, 2019

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.

@Jele0794
Copy link

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.

  • If the lexer is a custom one, it should contain the method generateModule so it can generate the rules on the output parser. If it doesn't, it won't work.
  • Whatever you pass to the 'yy' is overwritten on the generation with yy: {}, so you'll need to add it manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants