lezer-parser/lezer

How to get usable error messages?

unleashy opened this issue · 3 comments

Hello! Lezer is a brilliant parser generator, but one thing that is bothering me is that the strict error messages are very, very bare ("No parse at 42"), not telling much.

So my question is, is there any way to get better error messages? If not through Lezer then through some sort of algorithm I could implement in my programs? I would love some pointers, as tree nodes don’t seem to have much in the way of information for error messages.

Thank you!

Detailed error messages are out of scope for this package. Strict mode is sort of an afterthought, not really used in the main application (editor tooling) of this system.

For debugging setting the environment variable LOG to the value parse will give you (a lot) of output on what the parser is doing (which gets more readable if you compile your parser with the --names flag).

What are you doing with the parser in this case?

What are you doing with the parser in this case?

Live web editor for a programming language. I thought, since Lezer is already doing all the parsing with a handy grammar file to boot, I could just grab the syntax tree off of the CodeMirror state and use it for the compiler, but it seems that Lezer wasn’t quite meant for that sort of work?

Detailed error messages are out of scope for this package.

Yeah that’s fair 😅 correct me if I’m wrong but LR parsers do have a hard time emitting good error messages, right? So that would be a lot of work for just an editor parser.

I could just grab the syntax tree off of the CodeMirror state and use it for the compiler

That could work, but indeed, you won't get any information in your syntax error messages.

but LR parsers do have a hard time emitting good error messages, right?

They can do better than this if they store some more information, but yeah, you'll still only get something like "unexpected token X at line, char. Expected Y, Z, V, W, or U".