Skip to content

Commit b3b12f5

Browse files
committed
Fix: #30
1 parent fdfb16c commit b3b12f5

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

src/Hie/Cabal/Parser.hs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,28 @@ parseString = parseQuoted <|> unqualName
9494
unqualName :: Parser Text
9595
unqualName = takeWhile1 (not . (\c -> isSpace c || c == ','))
9696

97-
-- | Skip spaces and if end of line is reached, skip it as well and require that
98-
-- next one starts with indent.
99-
--
100-
-- Used for parsing fields.
101-
optSkipToNextLine :: Indent -> Parser ()
102-
optSkipToNextLine i = do
103-
skipMany $ satisfy (\c -> isSpace c && not (isEndOfLine c))
104-
skipMany $ skipSpace >> "--" >> takeTill isEndOfLine
105-
peekChar >>= \case
106-
Just c
107-
| isEndOfLine c ->
108-
endOfLine >> indent i $> ()
109-
_ -> pure ()
110-
11197
-- | Comma or space separated list, with optional new lines.
11298
parseList :: Indent -> Parser [Text]
113-
parseList i = sepBy parseString (optSkipToNextLine i >> skipMany (char ',') >> optSkipToNextLine i) <|> pure []
99+
parseList i = many (nl <|> sl)
100+
where
101+
sep = skipMany (char ',' <|> tabOrSpace)
102+
com = skipMany tabOrSpace >> "--" >> skipWhile (not . isEndOfLine)
103+
sl = do
104+
sep
105+
x <- parseString
106+
sep
107+
skipMany com
108+
pure x
109+
110+
nl = do
111+
skipMany emptyOrComLine <|> endOfLine
112+
_ <- indent i
113+
sep
114+
skipMany com
115+
x <- parseString
116+
sep
117+
skipMany com
118+
pure x
114119

115120
pathMain :: Indent -> [Text] -> Text -> [Text] -> [Text] -> Parser [Text]
116121
pathMain i p m o a =
@@ -153,7 +158,7 @@ skipBlockLine :: Indent -> Parser ()
153158
skipBlockLine i = (indent i >> skipToNextLine) <|> emptyOrComLine
154159

155160
emptyOrComLine :: Parser ()
156-
emptyOrComLine = skipMany tabOrSpace >> endOfLine <|> comment
161+
emptyOrComLine = (skipMany tabOrSpace >> endOfLine) <|> comment
157162

158163
tabOrSpace :: Parser Char
159164
tabOrSpace = char ' ' <|> char '\t'
@@ -171,9 +176,9 @@ field i f p =
171176
do
172177
i' <- indent i
173178
_ <- asciiCI f
174-
skipSpace
179+
skipMany tabOrSpace
175180
_ <- char ':'
176-
skipSpace
181+
skipMany tabOrSpace
177182
p' <- p $ i' + 1
178183
skipToNextLine
179184
pure p'

test/Spec.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,12 @@ libSection =
166166
\ exposed-modules:\n\
167167
\ Lib\n\
168168
\ other-modules:\n\
169-
\ Paths_implicit_hie\n\
169+
\ Paths_implicit_hie\n\
170170
\ hs-source-dirs:\n\
171-
\ src\n\
171+
\ src\n\
172172
\ ghc-options: -fspecialize-aggressively -Wall -Wincomplete-record-updates -Wincomplete-uni-patterns -fno-warn-unused-imports -fno-warn-unused-binds -fno-warn-name-shadowing -fwarn-redundant-constraints\n\
173173
\ build-depends:\n\
174-
\ attoparsec\n\
174+
\ attoparsec\n\
175175
\ , base >=4.7 && <5\n\
176176
\ , text\n\
177177
\ default-language: Haskell2010\n\

0 commit comments

Comments
 (0)