kach / nearley

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

Serializing errors when token contains BigInt #573

Open mt-xing opened 3 years ago

mt-xing commented 3 years ago

If I'm reading the source code correctly, nearley uses JSON.stringify to generate the errors it throws.

Unfortunately, as a result, if the token from a custom tokenizer includes a value field of type BigInt, rather than getting a useful error message, the actual error thrown is Type Error: Do not know how to serialize a BigInt, because JSON.stringify cannot serialize BigInts.

Is there a way to have nearley use a custom serializer for tokens when generating errors?