@@ -144,33 +144,33 @@ jsonField fn v
144144 | v == emptyArray = mempty
145145 | v == emptyString = mempty
146146 | otherwise = [Key. fromString (fromUTF8BS fn) .= v]
147- where
148- -- Should be added to aeson
149- emptyString :: Value
150- emptyString = String " "
147+ where
148+ -- Should be added to aeson
149+ emptyString :: Value
150+ emptyString = String " "
151151
152152jsonGenericPackageDescription :: GenericPackageDescription -> Value
153153jsonGenericPackageDescription gpd = jsonGenericPackageDescription' v gpd
154- where
155- v = specVersion $ packageDescription gpd
154+ where
155+ v = specVersion $ packageDescription gpd
156156
157157jsonGenericPackageDescription' :: CabalSpecVersion -> GenericPackageDescription -> Value
158158jsonGenericPackageDescription' v gpd =
159159 object $
160160 concat
161- [ jsonPackageDescription v (packageDescription gpd),
162- jsonSetupBuildInfo v (setupBuildInfo (packageDescription gpd)),
163- jsonGenPackageFlags v (genPackageFlags gpd),
164- jsonCondLibrary v (condLibrary gpd),
165- jsonCondSubLibraries v (condSubLibraries gpd),
166- jsonCondForeignLibs v (condForeignLibs gpd),
167- jsonCondExecutables v (condExecutables gpd),
168- jsonCondTestSuites v (condTestSuites gpd),
169- jsonCondBenchmarks v (condBenchmarks gpd)
161+ [ jsonPackageDescription v (packageDescription gpd)
162+ , jsonSetupBuildInfo v (setupBuildInfo (packageDescription gpd))
163+ , jsonGenPackageFlags v (genPackageFlags gpd)
164+ , jsonCondLibrary v (condLibrary gpd)
165+ , jsonCondSubLibraries v (condSubLibraries gpd)
166+ , jsonCondForeignLibs v (condForeignLibs gpd)
167+ , jsonCondExecutables v (condExecutables gpd)
168+ , jsonCondTestSuites v (condTestSuites gpd)
169+ , jsonCondBenchmarks v (condBenchmarks gpd)
170170 ]
171171
172172jsonPackageDescription :: CabalSpecVersion -> PackageDescription -> [Pair ]
173- jsonPackageDescription v pd@ PackageDescription {sourceRepos, setupBuildInfo} =
173+ jsonPackageDescription v pd@ PackageDescription {sourceRepos, setupBuildInfo} =
174174 jsonFieldGrammar v packageDescriptionFieldGrammar pd
175175 <> jsonSourceRepos v sourceRepos
176176 <> jsonSetupBuildInfo v setupBuildInfo
@@ -180,7 +180,7 @@ jsonSourceRepos v =
180180 concatMap (\ neRepos -> [" source-repository" .= NE. map (jsonSourceRepo v) neRepos]) . NE. nonEmpty
181181
182182jsonSourceRepo :: CabalSpecVersion -> SourceRepo -> Value
183- jsonSourceRepo v repo@ SourceRepo {repoKind} =
183+ jsonSourceRepo v repo@ SourceRepo {repoKind} =
184184 object $ jsonFieldGrammar v (sourceRepoFieldGrammar repoKind) repo
185185
186186jsonSetupBuildInfo :: CabalSpecVersion -> Maybe SetupBuildInfo -> [Pair ]
@@ -241,33 +241,33 @@ jsonCondBenchmark v (n, condTree) =
241241
242242jsonCondTree :: forall a . CabalSpecVersion -> JSONFieldGrammar' a -> CondTree ConfVar [Dependency ] a -> Value
243243jsonCondTree v grammar = toJSON . go . fmap fst . conv
244- where
245- go (CondFlat a ifs) =
246- KeyMap. fromListWith (<>) $
247- second (: [] )
248- <$> jsonFieldGrammar v grammar a ++ concatMap (\ (cv, a') -> second (ifc cv) <$> jsonFieldGrammar v grammar a') ifs
244+ where
245+ go (CondFlat a ifs) =
246+ KeyMap. fromListWith (<>) $
247+ second (: [] )
248+ <$> jsonFieldGrammar v grammar a ++ concatMap (\ (cv, a') -> second (ifc cv) <$> jsonFieldGrammar v grammar a') ifs
249249
250- ifc cv a = object [" if" .= showCondition cv, " then" .= a]
250+ ifc cv a = object [" if" .= showCondition cv, " then" .= a]
251251
252252data CondFlat v a = CondFlat a [(Condition v , a )]
253253 deriving (Show , Functor )
254254
255255conv :: forall v c a . CondTree v c a -> CondFlat v (a , c )
256256conv = goNode
257- where
258- goNode (CondNode a c ifs) =
259- CondFlat (a, c) (concatMap goBranch ifs)
260-
261- goBranch (CondBranch cond thenTree Nothing ) =
262- let (CondFlat a ifs) = goNode thenTree
263- in (cond, a) : fmap (first (cond `cAnd` )) ifs
264- goBranch (CondBranch cond thenTree (Just elseTree)) =
265- let (CondFlat a1 ifs1) = goNode thenTree
266- (CondFlat a2 ifs2) = goNode elseTree
267- in (cond, a1)
268- : (first (cond `cAnd` ) <$> ifs1)
269- ++ (cNot cond, a2)
270- : (first (cNot cond `cAnd` ) <$> ifs2)
257+ where
258+ goNode (CondNode a c ifs) =
259+ CondFlat (a, c) (concatMap goBranch ifs)
260+
261+ goBranch (CondBranch cond thenTree Nothing ) =
262+ let (CondFlat a ifs) = goNode thenTree
263+ in (cond, a) : fmap (first (cond `cAnd` )) ifs
264+ goBranch (CondBranch cond thenTree (Just elseTree)) =
265+ let (CondFlat a1 ifs1) = goNode thenTree
266+ (CondFlat a2 ifs2) = goNode elseTree
267+ in (cond, a1)
268+ : (first (cond `cAnd` ) <$> ifs1)
269+ ++ (cNot cond, a2)
270+ : (first (cNot cond `cAnd` ) <$> ifs2)
271271
272272test :: FilePath -> IO ()
273273test fn = do
0 commit comments