Skip to content

Migrate cabal.project parsing to parsec #7748

Closed as duplicate
Closed as duplicate

Description

@gbaz

Cabal.project parsing goes through legacy parsers and has a legacy -> current step. Its all rather awkward and also makes figuring out the actual grammar pretty difficult. It would be good to clean this up, capture the current grammar properly, and go through modern parsec parsers.

Activity

  1. added
    cabal-install: v2-build system
    re: code quality
    on Oct 14, 2021
  2. ptkato commented on Oct 14, 2021

    @ptkato
    Collaborator

    I think this could be tied to the exact printing work. A project file doesn't differ much, in terms of how it's written, from a cabal file.

  3. gbaz commented on Oct 14, 2021

    @gbaz
    CollaboratorAuthor

    Well, maybe. As it is, we don't have any sane parsing at all. It would be nice to reuse as much of the cabal parsing machinery as possible, treating projects as a special grammar, at which point we could leverage the exact-print stuff.

  4. phadej commented on Oct 14, 2021

    @phadej
    Collaborator

    The challenge is not using some specific new framework, as parsing the project file would be something like

    grammar :: ParsecFieldGrammar Project Project
    grammar = Project
        <$> C.monoidalFieldAla "packages"          (C.alaList' C.FSep PackageLocation) prjPackagesL
        <*> C.monoidalFieldAla "optional-packages" (C.alaList' C.FSep PackageLocation) prjOptPackagesL
        <*> C.monoidalFieldAla "constraints"       (C.alaList' C.CommaVCat NoCommas)   prjConstraintsL
        <*> C.monoidalFieldAla "allow-newer"       (C.alaList' C.CommaVCat NoCommas)   prjAllowNewerL
        <*> C.booleanFieldDef  "reorder-goals"                                         prjReorderGoalsL False
        <*> C.optionalFieldAla "max-backjumps"     Int'                                prjMaxBackjumpsL
        <*> C.optionalFieldDef "optimization"                                          prjOptimizationL OptimizationOn

    ... but actually figuring out what should or shouldn't be parsed.

    The cabal.project parser reuses parts ~/.cabal/config parsing, there is some magic tying command line parsing in as well.

    It's very messy, and not specified, there are only examples and some stuff which works, maybe intentionally, maybe accidentally.

    I wouldn't tie exact print work with this. They are different challenges.

    (EDIT: Just replicating what the current code does may be beneficial, already but i'm sure there are plenty of low-mid hanging cleanup&improvement opportunities).

  5. mmhat commented on Aug 15, 2023

    @mmhat

    I think this can be closed since it is a duplicate of #6101.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    cabal-install: v2-build systemre: code qualitytype: refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions