data Parser a c = Parser { runParser :: String -> Either [c] (a, String) }
and adding a combinator withContext c p = Parser \s -> case runParser p of
Left stackTrace = Left (c:stackTrace)
Right x = Right x
This allows you to write stuff like number = withContext "parsing a number" $ ...
addition = withContext "parsing addition expression" $ ...
expr = withContext "parsing a mathematical expression" $ ...
and combine that with a technique that keeps track of where you are in the string when failure occurs, you can pretty print that to something like:Failed to parse!
2 + 34.0O4
^
While: parsing a numberWhile: parsing addition expression
While: parsing a mathematical expression
I feel the criticism is valid because most parsers in production are done via hand without tooling or fancy techniques.
I don't see why you say that, parser combinators are just a structured way to compose recursive descent parsers, you can do everything with them that you can with any other hand-rolled parser. You don't even need to construct an AST at all, a mathematical expression "parser combinator" could just return a single number, the result of evaluating the expression.
What? Do you have any data you'd like to share?
I'm given to understand that e.g. the C++ compilers usually have a hand-coded, but AFAIUI that's mostly due to the complexity of actually parsing it (and fitting that into anything other than just raw code).
https://www.drdobbs.com/architecture-and-design/so-you-want-...
A common theme is that the parser generator does not provide you the tools to write the high quality error messages. Having used ANTLR and other tools, I believe it now that I'm trying to ship a real language.
(IME MegaParsec basically solves most of the issues.)
I suspect the difficulty of error handling or parsing a non-trivial language are exactly why few articles cover them. Crafting Interpreters¹ seems to be a notable exception here.
----
¹: https://www.craftinginterpreters.com/parsing-expressions.htm...
In fact, I would say Haskell-style parser combinators are the best way to satisfy those requirements in general.
[0] https://github.com/elm/compiler/commit/0e669b8ad076f64e450f2...
[1] https://github.com/elm/compiler/issues/1773#issuecomment-418... the same on master