nearley icon indicating copy to clipboard operation
nearley copied to clipboard

2.19.0: rules.map is not a function

Open anonymoussprocket opened this issue 5 years ago • 5 comments

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 avatar Dec 18 '19 22:12 anonymoussprocket

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.

anonymoussprocket avatar Dec 18 '19 23:12 anonymoussprocket

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

pablop94 avatar Feb 25 '20 02:02 pablop94

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.

jonminter avatar Mar 23 '20 20:03 jonminter

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.

pablop94 avatar Mar 25 '20 05:03 pablop94

No problem, glad I can help!

jonminter avatar Mar 25 '20 14:03 jonminter