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

2.19.0: rules.map is not a function #486

Open
anonymoussprocket opened this issue Dec 18, 2019 · 5 comments
Open

2.19.0: rules.map is not a function #486

anonymoussprocket opened this issue Dec 18, 2019 · 5 comments

Comments

@anonymoussprocket
Copy link

I'm using moo 0.5.0, with nearley 2.18.0. Upgrading to 0.5.1 and 2.19.0 respectively, then re-generating the parsers causes the following error:

TypeError: rules.map is not a function
at Function.Grammar.fromCompiled (/blah/blah/node_modules/nearley/lib/nearley.js:173:27)

The preceding call in the stack is const parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar));, where the grammar is compiled with nearleyc grammar.ne -o src/grammar.ts.

I'm using node 10.17.0 with typescript 3.5.3. Have you come across this issue?

@anonymoussprocket
Copy link
Author

anonymoussprocket commented Dec 18, 2019

in nearley/lib/nearley.js on line 167 the Grammar.fromCompiled = function(rules, start) { function can't find rules.ParserStart on line 170 because it's exported differently, it is now at rules.default.ParserStart.

@pablop94
Copy link

I'm having the same issue, is there a fix or workaround for it?

@jonminter
Copy link

I was having this issue. Workaround when you're importing your grammar do this:

import { default as myGrammar } from './my-grammar-module';
const myParser = new nearley.Parser(nearley.Grammar.fromCompiled(myGrammar));

Instead of:

import * myGrammar from './my-grammar-module';
const myParser = new nearley.Parser(nearley.Grammar.fromCompiled(myGrammar));

Unfortunately it seems this affects nearley-test as I get the same error message when trying to use the test CLI command.

@pablop94
Copy link

I was having this issue. Workaround when you're importing your grammar do this:

import { default as myGrammar } from './my-grammar-module';
const myParser = new nearley.Parser(nearley.Grammar.fromCompiled(myGrammar));

Instead of:

import * myGrammar from './my-grammar-module';
const myParser = new nearley.Parser(nearley.Grammar.fromCompiled(myGrammar));

Unfortunately it seems this affects nearley-test as I get the same error message when trying to use the test CLI command.

Thank you very much, you saved my project.
I have to modify some lines in my grammar, but it's working. I'll consider creating a fork with the resolution for this issue.

@jonminter
Copy link

No problem, glad I can help!

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

3 participants