`.cabal` files: Make a trailing colon for stanzas a parse failure
- Dominant language
- Haskell
- Stars
- 1.7k
- Forks
- 750
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 28
Description
#10525 made this mistake an error in `cabal.project` files:
source-repository-package:
type: git
location: https://github.com/parsonsmatt/foundation
tag: 688c32ccd9a951bc96dd09423a6e6684f091d510
subdir: basement
subdir: foundation
Now, it prints this error:
```
Error: [Cabal-7090]
Error parsing project file cabal.project:52:
'source-repository-package' is a stanza, not a field. Remove the trailing ':' to parse a stanza.
```
Unfortunately, `.cabal` files use a ~completely different system for parsing, so the fix in #10525 doesn't apply to those!
## Implementation strategy
For parsing `cabal.project`, the `parseFieldsAndSections` function (which #10525 modifies to error when stanzas are used as fields) is used with a list of top-level fields and a list of top-level stanzas (which themselves contain a grammar) to parse the file:
https://github.com/haskell/cabal/blob/5ec4dd1ddae3d29386ac435a50fd00b68c9566f6/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs#L1250-L1256
E.g. Here's the section description for `source-repository-package`:
https://github.com/haskell/cabal/blob/5ec4dd1ddae3d29386ac435a50fd00b68c9566f6/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs#L1805-L1826
And here's the grammar for the fields contained in a `source-repository-package`:
https://github.com/haskell/cabal/blob/5ec4dd1ddae3d29386ac435a50fd00b68c9566f6/cabal-install/src/Distribution/Client/Types/SourceRepo.hs#L101-L120
However, for `.cabal` files, the top-level grammar is defined manually:
https://github.com/haskell/cabal/blob/5ec4dd1ddae3d29386ac435a50fd00b68c9566f6/Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs#L97-L161
And the `goSections` parsing function just handles each field name manually:
https://github.com/haskell/cabal/blob/5ec4dd1ddae3d29386ac435a50fd00b68c9566f6/Cabal-syntax/src/Distribution/PackageDescription/Parsec.hs#L286
So we should adapt those into the system used by `cabal.project`.
Contributor guide
Assessment
This issue has not been assessed yet.