Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There's also parser combinators, which (for example) are used in GHC's parser.


When I lookup "ghc parser" I get this page [0] that says the GHC parser is built from Happy [1], a Yacc-like parser generator. Grammar is here [2].

Could you link me to where you see GHC's parser using parser combinators?

[0] https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compil...

[1] https://www.haskell.org/happy/

[2] https://gitlab.haskell.org/ghc/ghc/-/blob/master/compiler/GH...


I was scanning the GHC source by eye, and misunderstood a comment about the "parsing monad". (Alex, the equivalent of lex, uses monads to describe actions, but I thought that monads were the main interface to the lexer.) Thanks for the correction.


Agreed! I would say that parser combinators are the sweet spot and the right choice in most cases.

Scala has them as well, e.g.: https://com-lihaoyi.github.io/fastparse/

And the good thing is, you don't have to learn a completely new language/syntax, you can use the host language's syntax and you have full IDE support as well.


I find using parser combinators a joy. Makes parsing e.g. LateX somewhat straightforward


I've not come across parser combinators. Is there good introductory material?


It's Haskell-based, but here you go: http://dev.stephendiehl.com/fun/002_parsers.html


Agreed. I personally think of parser generator/parser combinator as similar to framework/library, where in the framework you have much less control and often have to rely on "escape hatches" to make custom stuff work. Whereas parser combinators are simply a library making implementing your parser much more convenient and expressive. You call the code, not the framework




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: