Skip to content

Commit 42d5855

Browse files
committed
Fix handling empty lists
1 parent ea51206 commit 42d5855

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Hie/Cabal/Parser.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ optSkipToNextLine i = do
105105
peekChar >>= \case
106106
Just c
107107
| isEndOfLine c ->
108-
endOfLine *> indent i $> ()
108+
endOfLine >> indent i $> ()
109109
_ -> pure ()
110110

111111
-- | Comma or space separated list, with optional new lines.
112112
parseList :: Indent -> Parser [Text]
113-
parseList i = sepBy parseString (optSkipToNextLine i *> skipMany (char ',') *> optSkipToNextLine i)
113+
parseList i = sepBy parseString (optSkipToNextLine i >> skipMany (char ',') >> optSkipToNextLine i) <|> pure []
114114

115115
pathMain :: Indent -> [Text] -> Text -> [Text] -> [Text] -> Parser [Text]
116116
pathMain i p m o a =

test/Spec.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ spec = do
116116
Comp Exe "gen-hie" "app/Hie/Executable/Helper.hs",
117117
Comp Exe "gen-hie" "app/Hie/Executable/Utils.hs"
118118
]
119+
describe "Should Succeed" $
120+
it "succesfully parses single other-modules" $
121+
("other-modules: test\ndefault-language: Haskell2011" :: Text) ~?> field 0 "other-modules" parseList
122+
`leavesUnconsumed` "default-language: Haskell2011"
123+
describe "Should Succeed" $
124+
it "succesfully parses empty other-modules" $
125+
("other-modules: test\ndefault-language: Haskell2011" :: Text) ~?> field 0 "other-modules" parseList
126+
`leavesUnconsumed` "default-language: Haskell2011"
119127

120128
exeSection :: Text
121129
exeSection =

0 commit comments

Comments
 (0)