Skip to content

Commit

Permalink
Add monoidField[Parsec] helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
hsyl20 committed Feb 25, 2025
1 parent facd40f commit 4a16b1b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1563,12 +1563,12 @@ legacyPackageConfigFieldDescrs =
parseTokenQ
configConfigureArgs
(\v conf -> conf{configConfigureArgs = v})
, simpleFieldParsec
, monoidFieldParsec
"flags"
dispFlagAssignment
parsecFlagAssignment
configConfigurationsFlags
(\v conf -> conf{configConfigurationsFlags = configConfigurationsFlags conf <> v})
(\v conf -> conf{configConfigurationsFlags = v})
, overrideDumpBuildInfo
]
. filterFields
Expand Down
29 changes: 29 additions & 0 deletions cabal-install/src/Distribution/Deprecated/ParseUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module Distribution.Deprecated.ParseUtils
, showFreeText
, field
, simpleField
, monoidField
, listField
, listFieldWithSep
, spaceListField
Expand All @@ -52,6 +53,7 @@ module Distribution.Deprecated.ParseUtils
, readPToMaybe
, fieldParsec
, simpleFieldParsec
, monoidFieldParsec
, listFieldParsec
, commaListFieldParsec
, commaNewLineListFieldParsec
Expand Down Expand Up @@ -254,6 +256,33 @@ simpleFieldParsec
simpleFieldParsec name showF readF get set =
liftField get set $ fieldParsec name showF readF

monoidField
:: Semigroup a
=> String
-> (a -> Doc)
-> ReadP a a
-> (b -> a)
-> (a -> b -> b)
-> FieldDescr b
monoidField name showF readF get set =
liftField get set' $ field name showF readF
where
set' xs b = set (get b <> xs) b

monoidFieldParsec
:: Semigroup a
=> String
-> (a -> Doc)
-> ParsecParser a
-> (b -> a)
-> (a -> b -> b)
-> FieldDescr b
monoidFieldParsec name showF readF get set =
liftField get set' $ fieldParsec name showF readF
where
set' xs b = set (get b <> xs) b


commaListFieldWithSepParsec
:: Separator
-> String
Expand Down

0 comments on commit 4a16b1b

Please sign in to comment.