`cabal.project` parser ignores the last package if it doesn't end in newline
This seems to happen with a leading newline too:
packages:
.
# some comment
another-package
<rant>
If only the cabal ecosystem had gone with JSON/TOML, like Rust Cargo does, rather than re-inventing their own formats ...
</rant>
In a cabal.project file, packages: foo is perfectly valid, but not recognized by a parser that insists that packages: is followed by a newline character:
https://github.com/srid/haskell-flake/blob/f16e7ac05b1f22b66ef05b7fcc8a96281bb2b749/nix/haskell-parsers/parser.nix#L25
Also packages: foo bar is valid syntax, which isn't recognized by a parser that insists on newline characters between package names.
https://github.com/srid/haskell-flake/blob/f16e7ac05b1f22b66ef05b7fcc8a96281bb2b749/nix/haskell-parsers/parser.nix#L26-L28
In the wild: https://github.com/tree-sitter/haskell-tree-sitter/blob/387494ab7f4efd9f4d3cdbf8e60ed55bc1f1688a/cabal.project
The official parser is implemented here: https://github.com/haskell/cabal/blob/84acb0e9510c82caae1c1bc4397aafca7f25f83a/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs#L1207-L1210 https://github.com/haskell/cabal/blob/84acb0e9510c82caae1c1bc4397aafca7f25f83a/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs#L1239-L1273 Yeah, that's a mouthful... agree to the rant. Maybe a tool like https://hackage.haskell.org/package/cabal2json could help (if it was maintained).
Part of the reason to reimplement it in Nix is to avoid "import from derivation", making it so that the flake attributes can be determined without doing any builds. It keeps things like nix build shell completions fast, among other benefits.