File tree Expand file tree Collapse file tree 2 files changed +20
-10
lines changed Expand file tree Collapse file tree 2 files changed +20
-10
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import Control.Applicative
6
6
import Control.Monad
7
7
import Data.Attoparsec.Text
8
8
import Data.Char
9
+ import Data.Functor
9
10
import Data.Maybe
10
11
import Data.Text (Text )
11
12
import qualified Data.Text as T
@@ -92,19 +93,24 @@ parseString = parseQuoted <|> unqualName
92
93
unqualName :: Parser Text
93
94
unqualName = takeWhile1 (not . (\ c -> isSpace c || c == ' ,' ))
94
95
96
+ -- | Skip spaces and if enf of line is reached, skip it as well and require that
97
+ -- next one starts with indent.
98
+ --
99
+ -- Used for parsing fields.
100
+ optSkipToNextLine :: Indent -> Parser ()
101
+ optSkipToNextLine i = do
102
+ skipMany $ satisfy (\ c -> isSpace c && not (isEndOfLine c))
103
+ mChar <- peekChar
104
+ case mChar of
105
+ Just c | isEndOfLine c ->
106
+ char c *> indent i $> ()
107
+ _ -> pure ()
108
+
109
+ -- | Comma or space separated list, with optional new lines.
95
110
parseList :: Indent -> Parser [Text ]
96
111
parseList i = items <|> (emptyOrComLine >> indent i >> items)
97
112
where
98
- items = do
99
- skipMany tabOrSpace
100
- h <- parseString
101
- skipMany tabOrSpace
102
- skipMany (char ' ,' )
103
- t <-
104
- items
105
- <|> (skipToNextLine >> indent i >> parseList i)
106
- <|> pure []
107
- pure $ h : t
113
+ items = sepBy parseString (optSkipToNextLine i *> skipMany (char ' ,' ) *> optSkipToNextLine i)
108
114
109
115
pathMain :: Indent -> [Text ] -> Text -> [Text ] -> [Text ] -> Parser [Text ]
110
116
pathMain i p m o a =
Original file line number Diff line number Diff line change @@ -86,6 +86,10 @@ spec = do
86
86
$ it " quoted list"
87
87
$ (" \" one\"\n two\n three3" :: Text ) ~> parseList 1
88
88
`shouldParse` [" one" , " two" , " three3" ]
89
+ describe " Should Succeed"
90
+ $ it " list with leading commas"
91
+ $ (" one\n , two\n , three3" :: Text ) ~> parseList 1
92
+ `shouldParse` [" one" , " two" , " three3" ]
89
93
90
94
exeSection :: Text
91
95
exeSection =
You can’t perform that action at this time.
0 commit comments