haskell / happy

The Happy parser generator for Haskell
Other
276 stars 85 forks source link

Support parser rule includes/modules #198

Open raehik opened 3 years ago

raehik commented 3 years ago

I'm working on some projects where we have multiple large Happy parsers, many of which reuse snippets or entire blocks of rules. We'd like to split some rules off into include-able files while staying platform-agnostic (I could easily solve it with some Bash, but then Windows will need its own solution, etc...). Having a Happy feature to allow "sharing" rules between parsers would help in refactoring larger parsers.

I've searched the internet and Happy code/docs and asked #haskell on Libera, but I'm not sure if there's any solution or precedent for this currently.

Ericson2314 commented 3 years ago

@int-index's and my long-term plan is to work on a Template-Haskell variant of happy that, among other benefits, should allow one to compute the grammar that is to be compiled at compile time however one likes. That ought to nail your use-case, but it will probably take a while as there some TH deficiencies to be fixed / worked around.

I would try to use C pre-processor in the meantime :(.

raehik commented 3 years ago

Thanks, great to hear. I wasn't sure if I could use Haskell's CPP extension, since I need to do it at parser generation, and Happy doesn't appear to run CPP (putting preprocessor directives in the rules section quickly gave me a parse error). It's only a maintainability problem, so we'll keep working around it while looking forward to the eventual improvements!