Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field Syntax Reference bugs #9793

Open
augustss opened this issue Mar 9, 2024 · 8 comments
Open

Field Syntax Reference bugs #9793

augustss opened this issue Mar 9, 2024 · 8 comments

Comments

@augustss
Copy link
Contributor

augustss commented Mar 9, 2024

In section 10, Field Syntax Reference there are many bugs.
Here are some I found today:

  • main-is: is a field for executables also
  • extra-source-files: does not require a comma
  • other-modules: does not require a comma
  • location: field is not described
  • subdir: field is not described
  • x-revision: field is not described
  • license-files: field is not described
  • cabal-version: is described to have the literal value 3.4, should be more general
  • exposed-modules: field is not described
  • nhc98-options: field is not described
  • import: field not describes

In the description of \ring and \bullet it's unclear what "spaces" means.
Is it a 0x20 character? Or can it also be a 0x0a? It seems to be the latter.

I will report more as I find them. This was from parsing a single .cabal file with my parser that follows section 10.

@gbaz
Copy link
Collaborator

gbaz commented Mar 10, 2024

Thank you! As I mentioned in the discussion, it would be much better if we generated parts of this from the code directly, otherwise it will always tend to get out of sync and be incomplete.

Some small notes:

I believe for the precise field syntax of cabal-version 3.4, then indeed 3.4 is the only allowable value for cabal-version. But that's not the right way to document it, lol.

on x-revision we should document in general an x-convention where such fields are disregarded by cabal.

In general I bet a lot of our comma lists should be optional comma lists.

and finally we don't have a section for the executable stanza at all.

@fendor
Copy link
Collaborator

fendor commented Mar 10, 2024

Thank you! As I mentioned in the discussion, it would be much better if we generated parts of this from the code directly, otherwise it will always tend to get out of sync and be incomplete.

I think it should be the other way around. Cabal file format should have a specification, not defined by the implementation. Otherwise, it becomes really difficult to implement a third party cabal file parser, as the author needs to understand the Cabal-syntax package, instead of an abstract specification.

@augustss
Copy link
Contributor Author

I think it should be the other way around. Cabal file format should have a specification, not defined by the implementation. Otherwise, it becomes really difficult to implement a third party cabal file parser, as the author needs to understand the Cabal-syntax package, instead of an abstract specification.

Yes!!! There should be a grammar for Cabal file format. This should be the specification. If it can be used to produce parsers, all the better. I find the current field syntax specification vexing. E.g., who uses explicit fixpoints to describe a grammar?

Also, defining fields as "monoidal" is ok, but unless you know what monoid it is, it doesn't really say much.

All in all, writing a parser for the Cabal file format has been a lot of guess work and testing.

@augustss
Copy link
Contributor Author

I believe for the precise field syntax of cabal-version 3.4, then indeed 3.4 is the only allowable value for cabal-version. But that's not the right way to document it, lol.

I've seen other values, and they seem to be accepted. Also, my Cabal is version 3.10.2.1, so "3.4" seems quite wrong.

@fendor
Copy link
Collaborator

fendor commented Mar 10, 2024

I've seen other values, and they seem to be accepted. Also, my Cabal is version 3.10.2.1, so "3.4" seems quite wrong.

Cabal file format version and Cabal version are two completely distinct values, in theory. It is not wrong, but quite confusing indeed, due to our insistence on naming collisions :)

@gbaz
Copy link
Collaborator

gbaz commented Mar 10, 2024

I think it should be the other way around. Cabal file format should have a specification, not defined by the implementation. Otherwise, it becomes really difficult to implement a third party cabal file parser, as the author needs to understand the Cabal-syntax package, instead of an abstract specification.

What I mean is we should be able to take the current implementation (and every prior version using the same parser format) and automatically derive a standard specification from them, programmatically.

We could then choose to evolve "spec first" or "implementation first" but the end result would be that we always have a proper spec that can be understood independently of the implementation, and that it is in sync with what the implementation actually does.

Related:
#9186
#7545

@augustss
Copy link
Contributor Author

augustss commented Mar 11, 2024

The flag stanza is also not in section 10.

@augustss
Copy link
Contributor Author

augustss commented Mar 12, 2024

I asked ChatGPT about a BNF grammar for Cabal files. It did surprisingly well. Better than the Cabal documentation. 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants