News for hackers. Stuff that matters.
Re:Writing parsers like it is 2017 by fmap on Tuesday August 15, 2017 @11:31AM (#15019152)
Some people have mentioned parser generators, but so far nobody has mentioned 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.

Re:Writing parsers like it is 2017 by jdf on Tuesday August 15, 2017 @01:33PM (#15020374)
There's a Rust parser generator called LALRPOP that is apparently inspired by Menhir.

https://github.com/nikomatsakis/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.

Re:Writing parsers like it is 2017 by krat0sprakhar on Tuesday August 15, 2017 @01:38PM (#15020435)
+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

[1] https://github.com/prakhar1989/JSJS/blob/master/src/parser.m...

Re:Writing parsers like it is 2017 by bd82 on Tuesday August 15, 2017 @12:24PM (#15019648)
This 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. :)

Re:Writing parsers like it is 2017 by ch4s3 on Tuesday August 15, 2017 @12:59PM (#15020007)
That's cool! I've never seen a parser generator that does that!