nearley
nearley copied to clipboard
2.19.0: rules.map is not a function
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?
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
.
I'm having the same issue, is there a fix or workaround for it?
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.
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.
No problem, glad I can help!