This commit is contained in:
Avi Dessauer 2020-04-30 20:51:44 -04:00
parent a3c3360bbc
commit 93cd9c7d93
3 changed files with 17 additions and 17 deletions

View File

@ -21,6 +21,6 @@ main = do
| otherwise -> stackHieYaml | otherwise -> stackHieYaml
when (null path) $ error "No .cabal file found!\n You may need to run stack build." when (null path) $ error "No .cabal file found!\n You may need to run stack build."
file <- T.readFile $ head path file <- T.readFile $ head path
case parseOnly parseSec file of case parseOnly parsePackage file of
Right r -> T.writeFile "hie.yaml" $ sOrC r Right r -> T.writeFile "hie.yaml" $ sOrC r
_ -> error "Could not parse *.cabal file" _ -> error "Could not parse *.cabal file"

View File

@ -24,19 +24,19 @@ data Component = Lib Path | Exe Name Path | Test Name Path
parseName :: Parser Text parseName :: Parser Text
parseName = "name" >> skipSpace >> char ':' >> parseString parseName = "name" >> skipSpace >> char ':' >> parseString
parseSec :: Parser Package parsePackage :: Parser Package
parseSec = parsePackage =
( do ( do
n <- parseName n <- parseName
(Package _ t) <- parseSec (Package _ t) <- parsePackage
pure $ Package n t pure $ Package n t
) )
<|> ( do <|> ( do
h <- parseComponent 0 h <- parseComponent 0
(Package n t) <- parseSec (Package n t) <- parsePackage
pure $ Package n (h : t) pure $ Package n (h : t)
) )
<|> (skipToNextLine >> parseSec) <|> (skipToNextLine >> parsePackage)
<|> pure (Package "" []) <|> pure (Package "" [])
parseComponent :: Indent -> Parser Component parseComponent :: Indent -> Parser Component

View File

@ -26,23 +26,23 @@ spec = do
$ libSection ~> parseLib 0 $ libSection ~> parseLib 0
`shouldParse` Lib "src" `shouldParse` Lib "src"
describe "Should Succeed" describe "Should Succeed"
$ it "successfully parses library section" $ it "successfully parses package"
$ fullFile ~> parseSec $ fullFile ~> parsePackage
`shouldParse` Package `shouldParse` Package
"implicit-hie" "implicit-hie"
[ Lib "src", [ Lib "src",
Exe "implicit-hie-exe" "app", Exe "implicit-hie-exe" "app",
Test "implicit-hie-test" "test" Test "implicit-hie-test" "test"
] ]
describe "Should Succeed" describe "Should Succeed"
$ it $ it
"successfully parses library section" "skips to end of block section"
$ let r = "test\n" $ let r = "test\n"
in (libSection <> r) ~?> parseLib 0 in (libSection <> r) ~?> parseLib 0
`leavesUnconsumed` r `leavesUnconsumed` r
describe "Should Succeed" describe "Should Succeed"
$ it "successfully generates stack hie.yaml" $ it "successfully generates stack hie.yaml"
$ (stackHieYaml <$> parseOnly parseSec fullFile) `shouldBe` Right stackHie $ (stackHieYaml <$> parseOnly parsePackage fullFile) `shouldBe` Right stackHie
fullFile :: Text fullFile :: Text
fullFile = "name: implicit-hie\n" <> libSection <> exeSection <> testSection fullFile = "name: implicit-hie\n" <> libSection <> exeSection <> testSection