Closed the-jasoney closed 1 year ago
I also get the same error, and I'm also using the typescript preprocessor:
TypeError: rules.map is not a function
at Function.Grammar.fromCompiled (/Users/audrey/.nvm/versions/node/v17.4.0/lib/node_modules/nearley/lib/nearley.js:172:27)
at Object.<anonymous> (/Users/audrey/.nvm/versions/node/v17.4.0/lib/node_modules/nearley/bin/nearley-test.js:27:31)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
Node.js v17.4.0
It turns out that the problem was that rules
was of the form:
{
default: { ... }
}
so locally, adding
if ("default" in rules) {
rules = rules.default
}
at the top of Grammar.fromCompiled
did the trick.
For any people looking for the answer to this problem: this repo seems to be dead, so the only way to solve this problem is to implement the above fix yourself.
I am using nearley with the typescript preprocessor and I get this error when I try to use nearley.test:
nearley-unparse seems to be working fine with a JS grammar.