4 ms·
There's also parser combinators, which (for example) are used in GHC's parser.
by thewakalix 5y ago
There's also parser combinators, which (for example) are used in GHC's parser.
- cosmic_quanta 5y agoI find using parser combinators a joy. Makes parsing e.g. LateX somewhat straightforward
- eatonphil 5y agoWhen 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/compiler/parser https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compil... [1] https://www.haskell.org/happy/ https://www.haskell.org/happy/ [2] https://gitlab.haskell.org/ghc/ghc/-/blob/master/compiler/GHC/Parser.y https://gitlab.haskell.org/ghc/ghc/-/blob/master/compiler/GH...
- thewakalix 5y agoI 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.
- valenterry 5y agoAgreed! 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/ 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.
- CornCobs 5y agoAgreed. 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