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
when (null path) $ error "No .cabal file found!\n You may need to run stack build."
file <- T.readFile $ head path
case parseOnly parseSec file of
case parseOnly parsePackage file of
Right r -> T.writeFile "hie.yaml" $ sOrC r
_ -> 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 = "name" >> skipSpace >> char ':' >> parseString
parseSec :: Parser Package
parseSec =
parsePackage :: Parser Package
parsePackage =
( do
n <- parseName
(Package _ t) <- parseSec
(Package _ t) <- parsePackage
pure $ Package n t
)
<|> ( do
h <- parseComponent 0
(Package n t) <- parseSec
(Package n t) <- parsePackage
pure $ Package n (h : t)
)
<|> (skipToNextLine >> parseSec)
<|> (skipToNextLine >> parsePackage)
<|> pure (Package "" [])
parseComponent :: Indent -> Parser Component

View File

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