kach / nearley

📜🔜🌲 Simple, fast, powerful parser toolkit for JavaScript.
https://nearley.js.org
MIT License
3.6k stars 232 forks source link

nearley-unparse doesn't work with Typescript #509

Open joereynolds opened 4 years ago

joereynolds commented 4 years ago

Pretty much what the title says.

I have a grammar with @preprocessor typescript and that is compiled with nearleyc statement.ne -o grammar.ts.

I then try and use nearley-unparse grammar.ts but I'm met with

function id(d: any[]): any { return d[0]; }
             ^

SyntaxError: Unexpected token ':'
    at wrapSafe (internal/modules/cjs/loader.js:983:16)
    at Module._compile (internal/modules/cjs/loader.js:1033:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10)
    at Module.load (internal/modules/cjs/loader.js:914:32)
    at Function.Module._load (internal/modules/cjs/loader.js:822:14)
    at Module.require (internal/modules/cjs/loader.js:956:19)
    at new require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/joe/.nvm/versions/node/v13.1.0/lib/node_modules/nearley/bin/nearley-unparse.js:20:15)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10)

My current workaround is to remove the .preprocessor, recompile it and then I can unparse it

kach commented 4 years ago

You should be able to compile with the --nojs option to remove preprocessors automatically.