mirror of
https://github.com/Avi-D-coder/implicit-hie.git
synced 2024-09-11 09:05:25 +03:00
Fix: #24 handle comments in lists
This commit is contained in:
parent
45165dcb21
commit
aed4155c91
@ -1,3 +1,4 @@
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Hie.Cabal.Parser where
|
||||
@ -93,25 +94,23 @@ parseString = parseQuoted <|> unqualName
|
||||
unqualName :: Parser Text
|
||||
unqualName = takeWhile1 (not . (\c -> isSpace c || c == ','))
|
||||
|
||||
-- | Skip spaces and if enf of line is reached, skip it as well and require that
|
||||
-- | Skip spaces and if end of line is reached, skip it as well and require that
|
||||
-- next one starts with indent.
|
||||
--
|
||||
-- Used for parsing fields.
|
||||
optSkipToNextLine :: Indent -> Parser ()
|
||||
optSkipToNextLine i = do
|
||||
skipMany $ satisfy (\c -> isSpace c && not (isEndOfLine c))
|
||||
mChar <- peekChar
|
||||
case mChar of
|
||||
skipMany $ skipSpace >> "--" >> takeTill isEndOfLine
|
||||
peekChar >>= \case
|
||||
Just c
|
||||
| isEndOfLine c ->
|
||||
char c *> indent i $> ()
|
||||
endOfLine *> indent i $> ()
|
||||
_ -> pure ()
|
||||
|
||||
-- | Comma or space separated list, with optional new lines.
|
||||
parseList :: Indent -> Parser [Text]
|
||||
parseList i = items <|> (emptyOrComLine >> indent i >> items)
|
||||
where
|
||||
items = sepBy parseString (optSkipToNextLine i *> skipMany (char ',') *> optSkipToNextLine i)
|
||||
parseList i = sepBy parseString (optSkipToNextLine i *> skipMany (char ',') *> optSkipToNextLine i)
|
||||
|
||||
pathMain :: Indent -> [Text] -> Text -> [Text] -> [Text] -> Parser [Text]
|
||||
pathMain i p m o a =
|
||||
|
20
test/Spec.hs
20
test/Spec.hs
@ -89,6 +89,26 @@ spec = do
|
||||
it "list with leading commas" $
|
||||
("one\n , two\n , three3" :: Text) ~> parseList 1
|
||||
`shouldParse` ["one", "two", "three3"]
|
||||
describe "Should Succeed" $
|
||||
it "list with a comment" $
|
||||
("foo\n -- need to include this too\n bar\n" :: Text) ~> parseList 1
|
||||
`shouldParse` ["foo", "bar"]
|
||||
describe "Should Succeed" $
|
||||
it "list with a comment" $
|
||||
("foo -- need to include this too\n bar\n" :: Text) ~> parseList 1
|
||||
`shouldParse` ["foo", "bar"]
|
||||
describe "Should Succeed" $
|
||||
it "list with a comment" $
|
||||
("foo -- need to include this too\n bar" :: Text) ~> parseList 1
|
||||
`shouldParse` ["foo", "bar"]
|
||||
describe "Should Succeed" $
|
||||
it "list with a comment" $
|
||||
("foo\n bar\n -- need to include this too" :: Text) ~> parseList 1
|
||||
`shouldParse` ["foo", "bar"]
|
||||
describe "Should Succeed" $
|
||||
it "list with a comment" $
|
||||
("foo\n bar -- need to include this too" :: Text) ~> parseList 1
|
||||
`shouldParse` ["foo", "bar"]
|
||||
describe "Should Succeed" $
|
||||
it "succesfully parses exe component with other-modules containing dots" $
|
||||
exeSection2 ~> parseExe 0
|
||||
|
Loading…
Reference in New Issue
Block a user