Fix handling empty lists

This commit is contained in:
Avi Dessauer 2020-11-23 11:01:21 -05:00
parent ea512066e5
commit 42d585560a
2 changed files with 10 additions and 2 deletions

View File

@ -105,12 +105,12 @@ optSkipToNextLine i = do
peekChar >>= \case
Just c
| isEndOfLine c ->
endOfLine *> indent i $> ()
endOfLine >> indent i $> ()
_ -> pure ()
-- | Comma or space separated list, with optional new lines.
parseList :: Indent -> Parser [Text]
parseList i = sepBy parseString (optSkipToNextLine i *> skipMany (char ',') *> optSkipToNextLine i)
parseList i = sepBy parseString (optSkipToNextLine i >> skipMany (char ',') >> optSkipToNextLine i) <|> pure []
pathMain :: Indent -> [Text] -> Text -> [Text] -> [Text] -> Parser [Text]
pathMain i p m o a =

View File

@ -116,6 +116,14 @@ spec = do
Comp Exe "gen-hie" "app/Hie/Executable/Helper.hs",
Comp Exe "gen-hie" "app/Hie/Executable/Utils.hs"
]
describe "Should Succeed" $
it "succesfully parses single other-modules" $
("other-modules: test\ndefault-language: Haskell2011" :: Text) ~?> field 0 "other-modules" parseList
`leavesUnconsumed` "default-language: Haskell2011"
describe "Should Succeed" $
it "succesfully parses empty other-modules" $
("other-modules: test\ndefault-language: Haskell2011" :: Text) ~?> field 0 "other-modules" parseList
`leavesUnconsumed` "default-language: Haskell2011"
exeSection :: Text
exeSection =