[Haskell-cafe] Re: ANNOUNCE: grammar-combinators 0.1 (initial
release): A parsing library of context-free grammar combinators
James Andrew Cook
mokus at deepbondi.net
Wed Sep 8 08:28:06 EDT 2010
On Sep 8, 2010, at 7:49 AM, Johannes Waldmann wrote:
> then you'll get more static guarantees (e.g., context-freeness)
> but you need extra (type-level, or even syntax-level) machinery
> to handle grammars. Convince me that it's worth it ...
Those guarantees, along with just the fact that the parser specification is data rather than a black-box function, explicitly make possible some very cool stuff, not least of which is true parser-generator-quality parsers. Just like a regex can be compiled once and then run repeatedly very fast, a context-free grammar can be compiled once to a stack-machine specification and run repeatedly. That compilation process is highly nonlocal and would never be possible with, e.g., the Parsec approach. On the other hand, parser generators such as Happy (which perform just such a transformation) cannot allow you to construct a grammar at run-time.
Even if you end up deploying a parser using a different framework, the grammar transformation stuff is pretty cool too. By specifying your grammar in this system, you get to play around with it, transform it, etc., and see what the transformed grammar looks like.
Incidentally, it'd be pretty nifty if someone made a Happy backend, or even just a TH snippet, that generated a grammar-combinators grammar and semantic action from a Happy parser specification.
-- James
More information about the Haskell-Cafe
mailing list