Hacker News new | ask | show | jobs
by marssaxman 325 days ago
I have never found parser generators to be worth the hassle. Recursive descent with a little Pratt-style precedence climbing is all you need.
1 comments

Agree completely and I’ve used a bunch of them and also functional combinator libraries. I‘d go further and say the recursive descent and Pratt approach is the way if you want to offer useful error messages and feedback to the user. They’re also trivial to debug and test unlike any generation based approach.
>functional combinator libraries

By that, do you mean parser combinators?

Yes - but this was decades ago so my memory is hazy. It was with an early Haskell variant called Gofer - which had a nice feature which allowed using list comprehension notation with arbitrary monads - which for simple grammars produced very readable - even beautiful - parser code. But like with parser generators, once the grammar became complex, the beauty and simplicity disappeared.

Actually I wish this generalization of list comprehensions had been taken up by Haskell or other languages. Haskell decided on the do notation while Python users these days seem to shun the feature.

ghc has the the MonadComprehension extension which does what you desire

https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/mona...

Thanks.

On a side note, I do use Python list comprehensions, and like them.