bnfc icon indicating copy to clipboard operation
bnfc copied to clipboard

how-to cabal

Open ScottFreeCode opened this issue 11 months ago • 3 comments

Maybe this belongs on the website repo, but, would it be helpful to have a couple examples somewhere of how to automate generating code with BNFC as part of the build process?

I recall (would take more time to track down) that there are issues around "can Cabal be taught to use BNFC like it uses Happy and Alex?" To which the answer is "Well, not like it uses Happy and Alex, no, since with BNFC there isn't a one-to-one correspondence between input files and generated files."

I figured out how to do it using Setup.hs instead.

I have a couple gists here you could base examples off of: https://gist.github.com/ScottFreeCode/9b0ea3e52fa56c93ea8ca14791e55bb4

One is a simple single package. Another is my attempt at splitting it up into two packages (say, if you want a library implementing a language but then separately want an executable interpreter). Both also demonstrate wrapping in Nix (which can be safely ignored as it doesn't affect the Haskell / Cabal code! Well, if you do use Nix, you have to either nix-build or use Cabal's v1 commands if you're working inside nix-shell, but I am talking with other developers in other issues about that problem.) Alongside them are a couple equivalent examples without BNFC, which you can use for comparison to see what is BNFC-specific / added in the BFNC ones.

Anyhow, I hope that is helpful someway or another.

ScottFreeCode avatar Jul 26 '23 05:07 ScottFreeCode