Skip to content

Commit 6d5f18a

Browse files
committed
foo
1 parent 52052e4 commit 6d5f18a

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

cabal-install-parsers/src/Cabal/Index.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ indexMetadata indexFilepath mindexState = do
399399

400400
f :: Maybe TmpPackageInfo -> Maybe TmpPackageInfo
401401
f Nothing = Just TmpPackageInfo
402-
{ tmpPiVersions = Map.singleton ver TmpReleaseInfo
402+
{ tmpPiVersions = Map.singleton ver TmpReleaseInfo
403403
{ tmpRiRevision = 0
404404
, tmpRiTarOffset = offset
405405
, tmpRiCabalHash = Just digest

cabal-install-parsers/src/Cabal/Project.hs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module Cabal.Project (
2828

2929
import Control.DeepSeq (NFData (..))
3030
import Control.Exception (Exception (..), throwIO)
31+
import Control.Monad (unless)
3132
import Control.Monad.IO.Class (liftIO)
3233
import Control.Monad.Trans.Except (ExceptT, runExceptT, throwE)
3334
import Data.Bifoldable (Bifoldable (..))
@@ -235,6 +236,12 @@ parseProject = parseWith $ \fields0 -> do
235236
-- >>> pp $ fmap (fmap prjPackages) $ parseProjectWithConditionals "cabal.project" $ fromString $ unlines [ "packages: foo bar/*.cabal", "if impl(ghc >=9)", " packages: quu", "if impl(ghc >=10)", " packages: zoo" ]
236237
-- CondTree ["foo","bar/*.cabal"] _ [CondBranch _ (CondTree ["quu"] _ []) Nothing,CondBranch _ (CondTree ["zoo"] _ []) Nothing]
237238
--
239+
-- >>> pp $ fmap (fmap prjPackages) $ parseProjectWithConditionals "cabal.project" $ fromString $ unlines [ "packages: foo bar/*.cabal", "if impl(ghc >=9)", " packages: quu", "else", " packages: zoo" ]
240+
-- CondTree ["foo","bar/*.cabal"] _ [CondBranch _ (CondTree ["quu"] _ []) (Just CondTree ["zoo"] _ [])]
241+
--
242+
-- >>> pp $ fmap (fmap prjPackages) $ parseProjectWithConditionals "cabal.project" $ fromString $ unlines [ "packages: foo bar/*.cabal", "if impl(ghc >=9)", " packages: quu", "elif impl(ghc >=10)", " packages: zoo", "else", " packages: yyz" ]
243+
-- CondTree ["foo","bar/*.cabal"] _ [CondBranch _ (CondTree ["quu"] _ []) (Just CondTree [] _ [CondBranch _ (CondTree ["zoo"] _ []) (Just CondTree ["yyz"] _ [])])]
244+
--
238245
parseProjectWithConditionals :: FilePath -> ByteString -> Either (ParseError NonEmpty) (C.CondTree C.ConfVar () (Project Void String String))
239246
parseProjectWithConditionals = parseWith $ \fields0 -> flip parseCondTree fields0 $ \fields1 sections -> do
240247
let fields2 = M.filterWithKey (\k _ -> k `elem` knownFields) fields1
@@ -452,9 +459,9 @@ parseCondTree subparse = go
452459
-> C.ParseResult ([C.Section C.Position], [C.CondBranch C.ConfVar () a])
453460
goIfs accS accB [] = do
454461
return (accS [], accB [])
455-
goIfs accS accB (C.MkSection (C.Name pos name) test fields : sections)
462+
goIfs accS accB (C.MkSection (C.Name pos name) args fields : sections)
456463
| name == "if" = do
457-
test' <- C.parseConditionConfVar test
464+
test' <- C.parseConditionConfVar args
458465
fields' <- go fields
459466
goElse (C.CondBranch test' fields') accS accB sections
460467
| name == "else" = do
@@ -472,13 +479,17 @@ parseCondTree subparse = go
472479
-> ([C.CondBranch C.ConfVar () a] -> [C.CondBranch C.ConfVar () a])
473480
-> [C.Section C.Position]
474481
-> C.ParseResult ([C.Section C.Position], [C.CondBranch C.ConfVar () a])
475-
goElse _make _accS _accB (C.MkSection (C.Name pos name) _args _fields : _sections)
482+
goElse make accS accB (C.MkSection (C.Name pos name) args fields : sections)
476483
| name == "else" = do
477-
C.parseFailure pos "else is not supported yet"
478-
return ([], [])
484+
unless (null args) $ C.parseFailure pos "arguments passed to else"
485+
fields' <- go fields
486+
let condTree = make (Just fields')
487+
goIfs accS (accB . (condTree :)) sections
479488
| name == "elif" = do
480-
C.parseFailure pos "elif is not supported yet"
481-
return ([], [])
489+
test' <- C.parseConditionConfVar args
490+
fields' <- go fields
491+
emptyA <- subparse mempty []
492+
goElse (make . Just . C.CondNode emptyA () . pure . C.CondBranch test' fields') accS accB sections
482493
goElse make accS accB sections = do
483494
let condTree = make Nothing
484495
goIfs accS (accB . (condTree :)) sections

0 commit comments

Comments
 (0)