Skip to content

Commit 52052e4

Browse files
committed
foo
1 parent 875a5dd commit 52052e4

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ infixl 1 <&>
7575

7676
-- $setup
7777
-- >>> :set -XOverloadedStrings
78+
-- >>> import Data.String (fromString)
79+
-- >>> import qualified Distribution.PackageDescription as C
80+
-- >>> import Text.Show (showListWith)
81+
-- >>> import Data.Functor.Classes (liftShowsPrec)
82+
-- >>> let sB (C.CondBranch c t f) = showString "CondBranch _ " . showParen True (sT t) . showChar ' ' . liftShowsPrec (\_ -> sT) undefined 11 f; sT (C.CondNode x c xs) = showString "CondTree " . showsPrec 11 x . showString " _ " . showListWith sB xs
83+
-- >>> pp x = putStrLn (either show (flip sT "") x)
7884

7985
-- | @cabal.project@ file
8086
data Project uri opt pkg = Project
@@ -220,13 +226,14 @@ parseProject = parseWith $ \fields0 -> do
220226

221227
-- | Parse project files with conditionals.
222228
--
223-
-- >>> fmap (fmap prjPackages) $ parseProjectWithConditionals "cabal.project" "packages: foo bar/*.cabal"
224-
-- Right (CondNode {condTreeData = ["foo","bar/*.cabal"], condTreeConstraints = (), condTreeComponents = []})
229+
-- >>> pp $ fmap (fmap prjPackages) $ parseProjectWithConditionals "cabal.project" "packages: foo bar/*.cabal"
230+
-- CondTree ["foo","bar/*.cabal"] _ []
225231
--
226-
-- TODO:
232+
-- >>> pp $ fmap (fmap prjPackages) $ parseProjectWithConditionals "cabal.project" $ fromString $ unlines [ "packages: foo bar/*.cabal", "if impl(ghc >=9)", " packages: quu" ]
233+
-- CondTree ["foo","bar/*.cabal"] _ [CondBranch _ (CondTree ["quu"] _ []) Nothing]
227234
--
228-
-- >>> fmap (fmap prjPackages) $ parseProjectWithConditionals "cabal.project" "packages: foo bar/*.cabal\nif impl(ghc >=9)\n packages: quu"
229-
-- Right (CondNode {condTreeData = ["foo","bar/*.cabal"], condTreeConstraints = (), condTreeComponents = []})
235+
-- >>> 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" ]
236+
-- CondTree ["foo","bar/*.cabal"] _ [CondBranch _ (CondTree ["quu"] _ []) Nothing,CondBranch _ (CondTree ["zoo"] _ []) Nothing]
230237
--
231238
parseProjectWithConditionals :: FilePath -> ByteString -> Either (ParseError NonEmpty) (C.CondTree C.ConfVar () (Project Void String String))
232239
parseProjectWithConditionals = parseWith $ \fields0 -> flip parseCondTree fields0 $ \fields1 sections -> do
@@ -465,16 +472,13 @@ parseCondTree subparse = go
465472
-> ([C.CondBranch C.ConfVar () a] -> [C.CondBranch C.ConfVar () a])
466473
-> [C.Section C.Position]
467474
-> C.ParseResult ([C.Section C.Position], [C.CondBranch C.ConfVar () a])
468-
goElse make accS accB [] = do
469-
let condTree = make Nothing
470-
return (accS [], accB [condTree])
471475
goElse _make _accS _accB (C.MkSection (C.Name pos name) _args _fields : _sections)
472476
| name == "else" = do
473477
C.parseFailure pos "else is not supported yet"
474478
return ([], [])
475479
| name == "elif" = do
476480
C.parseFailure pos "elif is not supported yet"
477481
return ([], [])
478-
goElse make accS accB (section : sections) = do
482+
goElse make accS accB sections = do
479483
let condTree = make Nothing
480-
goIfs (accS . (section :)) (accB . (condTree :)) sections
484+
goIfs accS (accB . (condTree :)) sections

0 commit comments

Comments
 (0)