You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add support in cabal to build bnf files using bnfc (like what is done with alex and happy). This would, among other things, make bnfc own compilation easier.
Yes, one could modify Setup.lhs to include code that generates the LBNF parser from the BNF.cf file, using BNFC. Currently Setup is the default script:
However, I don't see the point really. It seems better to have the BNFC-generated LBNF parser committed to the repo and included in the sdist tarball to avoid boot-strapping issues.
However, I don't see the point really. It seems better to have the
BNFC-generated LBNF parser committed to the repo and included in the
sdist tarball to avoid boot-strapping issues.
The point is that Cabal will do that for you automatically, i.e. it will
generate the source code and include it in the generater sdist tarball.
Checking generating source code into the git repository, however, is a
really bad idea because people will forget to update those files. This
will happen a couple of times, and then you'll decide that you'll need
some automatism to ensure the generated files up-to-date. That
automatism is Cabal.
@peti, I agree that it would be nicer if Cabal would know about the BNFC-generated files.
I did some research but did not find out how to teach Cabal about BNFC. Cabal seems to have a set of hardwired build-tools it knows about, like happy, alex etc., but there is no plugin mechanism I know of that would allow me to integrate BNFC. I would have to add it to the Cabal sources, it seems. Am I right?
@fgaz : Maybe you have some information about the build-tool handling in Cabal?
(Besides the technical difficulties, there is a bit of concern about backwards compatibility of BNFC. Later versions of BNFC might change the interface the generated files expose, so that code relying on a certain interface would not work with file generated by a newer BNFC. Of course, if one is worried about that, one can always commit the BNFC generated files to the source tree and not invoke BNFC in the build process.)
Later versions of BNFC might change the interface the generated files expose, so that code relying on a certain interface would not work with file generated by a newer BNFC
If correct version bounds are used on build-tool-depends (and if bnfc follows the PVP), this is not a concern.
Checking generating source code into the git repository, however, is a
really bad idea because people will forget to update those files. This
will happen a couple of times, and then you'll decide that you'll need
some automatism to ensure the generated files up-to-date. That
automatism is Cabal.
Or CI :)
One could set up CI so that it checks that preprocessor(source) == generated
Another nice way of treating generated files, IMO, is to only include them in release tarballs. This way:
The repo remains clean
The tarballs (the only source users should need to build) do not need preprocessing
There is no way for the generated files to get out of sync, if they are generated together with the tarball
It's not necessarily bad to wrap cabal, or to have some preprocessing steps for development/distribution, especially if this avoids a custom Setup. Cabal itself does this (though for BC reasons).
So a first step could be to have the Haskell backend of BNFC generate a Setup.hs script that does the correct invocation of BNFC. Once the logic has been found out, one could look at integrating BNFC as native build-tool into Cabal. Not sure what their policy is, though, if they would accept new hard-wired build tools.
@fgaz: Since I have you here, do you know how the hardwiring of e.g. happy works? Happy has several options, but in the cabal file I have no place to declare the options for invoking happy, do I? The build-tools field only accepts version bounds on happy and the like, no options for the invocation.
P.S.: There is PR #173 to create a cabal file. Maybe this can be extended to also create the Setup file.
As far as I know there's no way to pass options to preprocessors. One way of working around that could be to accept options in the .cf file itself, like GHC language pragmas.
Once the logic has been found out, one could look at integrating BNFC as native build-tool into Cabal. Not sure what their policy is, though, if they would accept new hard-wired build tools.
I just had a chat in #hackage on freenode and no, they would not. On the other hand, they're open to the possibility of adding extensible preprocessing in Cabal
Checking generating source code into the git repository, however, is a really bad idea because people will forget to update those files.
If you use a front-end to version control like magit which puts changed files in your face, you won't easily forget to update. However, it is still a bad idea, since it can be a nuisance if you have merge conflicts in these generated files. Version control should really have the concept of a generated file with its dependencies, then it would know that such files are not precious and simply move in sync with the files they are generated from...
Activity
peti commentedon Mar 1, 2013
I've done that for the
cabal2nixutility at https://github.com/NixOS/cabal2nix/tree/ebnf-parser-for-nix. Check out the Setup.hs file.andreasabel commentedon Nov 7, 2020
Yes, one could modify
Setup.lhsto include code that generates the LBNF parser from theBNF.cffile, using BNFC. Currently Setup is the default script:bnfc/source/Setup.lhs
Lines 1 to 6 in fb85ff1
However, I don't see the point really. It seems better to have the BNFC-generated LBNF parser committed to the repo and included in the sdist tarball to avoid boot-strapping issues.
peti commentedon Nov 9, 2020
andreasabel commentedon Nov 11, 2020
@peti, I agree that it would be nicer if Cabal would know about the BNFC-generated files.
I did some research but did not find out how to teach Cabal about BNFC. Cabal seems to have a set of hardwired build-tools it knows about, like happy, alex etc., but there is no plugin mechanism I know of that would allow me to integrate BNFC. I would have to add it to the Cabal sources, it seems. Am I right?
@fgaz : Maybe you have some information about the build-tool handling in Cabal?
(Besides the technical difficulties, there is a bit of concern about backwards compatibility of BNFC. Later versions of BNFC might change the interface the generated files expose, so that code relying on a certain interface would not work with file generated by a newer BNFC. Of course, if one is worried about that, one can always commit the BNFC generated files to the source tree and not invoke BNFC in the build process.)
fgaz commentedon Nov 11, 2020
@andreasabel
Yes. Either that, or a custom setup has to be used
The relevant module is
Cabal.Distribution.Simple.PreProcess. There are some comments on how it works in there.If correct version bounds are used on
build-tool-depends(and if bnfc follows the PVP), this is not a concern.fgaz commentedon Nov 11, 2020
@peti
Or CI :)
One could set up CI so that it checks that
preprocessor(source) == generatedAnother nice way of treating generated files, IMO, is to only include them in release tarballs. This way:
It's not necessarily bad to wrap cabal, or to have some preprocessing steps for development/distribution, especially if this avoids a custom Setup. Cabal itself does this (though for BC reasons).
andreasabel commentedon Nov 11, 2020
So a first step could be to have the Haskell backend of BNFC generate a
Setup.hsscript that does the correct invocation of BNFC. Once the logic has been found out, one could look at integrating BNFC as native build-tool into Cabal. Not sure what their policy is, though, if they would accept new hard-wired build tools.@fgaz: Since I have you here, do you know how the hardwiring of e.g.
happyworks? Happy has several options, but in the cabal file I have no place to declare the options for invokinghappy, do I? Thebuild-toolsfield only accepts version bounds onhappyand the like, no options for the invocation.P.S.: There is PR #173 to create a cabal file. Maybe this can be extended to also create the
Setupfile.fgaz commentedon Nov 11, 2020
As far as I know there's no way to pass options to preprocessors. One way of working around that could be to accept options in the .cf file itself, like GHC language pragmas.
fgaz commentedon Nov 11, 2020
I just had a chat in #hackage on freenode and no, they would not. On the other hand, they're open to the possibility of adding extensible preprocessing in Cabal
andreasabel commentedon Dec 21, 2020
See also this discussion on adding BNFC support to cabal: haskell/cabal#6726
andreasabel commentedon Dec 21, 2020
@peti wrote:
If you use a front-end to version control like
magitwhich puts changed files in your face, you won't easily forget to update. However, it is still a bad idea, since it can be a nuisance if you have merge conflicts in these generated files. Version control should really have the concept of a generated file with its dependencies, then it would know that such files are not precious and simply move in sync with the files they are generated from...