haskell / happy

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

Get rid of template preprocessing #179

Closed Ericson2314 closed 3 years ago

Ericson2314 commented 3 years ago

Instead of preprocessing an outer layer of CPP when building happy, just always produce code that uses CPP. Combined with #175, this means happy now has a perfectly bog standard build system, with Makefiles and extra steps strictly optional.

I gather Hugs, and possibly other Haskell implementations, out of the box doesn't support CPP, but I don't want this to stop us. Those can just manually run CPP on the generated code first.

Contains #175 and #178

int-index commented 3 years ago

I was actually hoping we'd move in the opposite direction w.r.t. CPP, so that the output of happy is proper Haskell, not Haskell+CPP.

Otherwise I don't see how we could achieve #149

Ericson2314 commented 3 years ago

@int-index Well in the short term, I think it's really import that Happy and Alex have "bog standard" build systems so that we can make them submodules in GHC and never have to do things like https://hackage.haskell.org/package/alex-3.2.6/changelog that lead to https://gitlab.haskell.org/ghc/ghc/-/issues/19099 again. And the submodule would allow us to iterate on happy and TH in tandem for #149 too.

Now, I formally thought that CPP was an impediment for #149 too, but I think I have a pretty fun solution for this. Suppose we follow TTG and instead of having just:

data Dec = ...

we have

data Dec' a = ...
          | XDec a
type Dec = Dec' NoExtCon

Now we can do

[d|
   foo = blah
   bar = blah
   $(XDec $ CppIf "Condition" [d| ... |] CppEndif)
|] :: Dec' Cpp

CPP + TH without polluting TH itself with such a toxin!


Of course, we might still want to get rid of CPP anyways, because it's gross. I don't have a problem with e.g. turning all the templates into quotes that are composed properly on the happy side, but I suspect we'll want that extension to TH anyways.

simonmar commented 3 years ago

Seems like a good idea.