3 ms·
Some people have mentioned parser generators, but so far nobody has mentioned Menhir (http://gallium.inria.fr/~fpottier/menhir/ http://gallium.inria.fr/~fpottie
by fmap 9y ago
Some people have mentioned parser generators, but so far nobody has mentioned Menhir (http://gallium.inria.fr/~fpottier/menhir/ http://gallium.inria.fr/~fpottier/menhir/).
It's an LR(1) parser generator for OCaml and Coq with a lot of extremely interesting features, such as genuinely good debugging support for grammars and the ability of generating error messages by example.
What this means is that after you write down your grammar, Menhir will give you examples of all the possible syntax errors that could occur. You can then write error messages for each case and get a parser with built-in error reporting for syntax errors.
This works a lot better than you'd think and I really wonder why nobody else implements this feature. Or for that matter, why they're not advertising it on the webpage! If you want to know more, look in the manual, section 11.
- bd82 9y agoThis is a really great way to customize error messages and ensure all error messages have been customized (or at least handled). I think I'm going to try and implement this in a parsing library I develop. :)
- ch4s3 9y agoThat's cool! I've never seen a parser generator that does that!
- jdf 9y agoThere's a Rust parser generator called LALRPOP that is apparently inspired by Menhir. https://github.com/nikomatsakis/lalrpop https://github.com/nikomatsakis/lalrpop http://smallcultfollowing.com/babysteps/blog/2016/03/02/nice-errors-in-lalrpop/ http://smallcultfollowing.com/babysteps/blog/2016/03/02/nice... I've never used Menhir so I can't compare how similar they are in practice, but I've enjoyed the times I played with LALRPOP much more than the many times I've battled various yacc derivatives.
- krat0sprakhar 9y ago+100 this! Menhir is really awesome and super usable parser generators. We used it to for JSJS [0], and you can see for yourself that the rules are quite easy to understand for a non-trivial grammar. [0] http://jsjs-lang.org http://jsjs-lang.org [1] https://github.com/prakhar1989/JSJS/blob/master/src/parser.mly https://github.com/prakhar1989/JSJS/blob/master/src/parser.m...