Crash (unknown symbol type) when custom token matcher expected
See original GitHub issueI’m running into an issue when using a custom token matcher. If there is a syntax error in the input, where nearley sees some token but is expecting a custom token matcher instead, it crashes instead of producing an error message.
This can be seen by passing the input ["print", "blah", 12, ";", ";"]
to the example grammar from the documentation. This results in the following error:
/home/willem/Git/nearley-test/node_modules/nearley/lib/nearley.js:402
throw new Error('Unknown symbol type: ' + symbol);
^
Error: Unknown symbol type: [object Object]
at Parser.getSymbolDisplay (/home/willem/Git/nearley-test/node_modules/nearley/lib/nearley.js:402:19)
at Parser.<anonymous> (/home/willem/Git/nearley-test/node_modules/nearley/lib/nearley.js:363:38)
at Array.forEach (<anonymous>)
at Parser.reportError (/home/willem/Git/nearley-test/node_modules/nearley/lib/nearley.js:360:21)
at Parser.feed (/home/willem/Git/nearley-test/node_modules/nearley/lib/nearley.js:314:42)
at Object.<anonymous> (/home/willem/Git/nearley-test/test-parser.js:6:8)
at Module._compile (internal/modules/cjs/loader.js:1121:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
at Module.load (internal/modules/cjs/loader.js:976:32)
at Function.Module._load (internal/modules/cjs/loader.js:884:14)
This seemingly comes from the procedure that is constructing the error output (maybe related to #479?). I tried modifying nearley.js
to print symbol
, but that is just an empty object {}
. Returning an empty string instead of throwing an error fixes the crash, but this results in the token name displayed as empty in the error output (not really helpful…)
(node -v
: v13.3.0, npm -v
: 6.13.1, nearleyc -v
: 2.19.0)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top GitHub Comments
This should be fixed! Thank you @airportyh
👍