wren romano avatar wren romano committed babdc87

Data.Attoparsec.Combinator: added sepEndBy1 and sepEndBy.

Comments (0)

Files changed (1)

Data/Attoparsec/Combinator.hs

     , manyTill
     , sepBy
     , sepBy1
+    , sepEndBy
+    , sepEndBy1
     , skipMany
     , skipMany1
     , eitherP
 sepBy1 p s = scan
     where scan = liftA2 (:) p ((s *> scan) <|> pure [])
 
+-- | @sepEndBy1 p sep@ parses /one/ or more occurrences of @p@,
+-- separated and optionally ended by @sep@. Returns a list of the
+-- values returned by @p@.
+sepEndBy1 :: Alternative f => f a -> f s -> f [a]
+sepEndBy1 p s = scan
+    where scan = liftA2 (:) p ((s *> (scan <|> pure [])) <|> pure [])
+
+-- | @sepEndBy p sep@ parses /zero/ or more occurrences of @p@,
+-- separated and optionally ended by @sep@, i.e., Haskell style
+-- statements. Returns a list of the values returned by @p@.
+sepEndBy :: Alternative f => f a -> f s -> f [a]
+sepEndBy p s = sepEndBy1 p s <|> return []
+
 -- | @manyTill p end@ applies action @p@ /zero/ or more times until
 -- action @end@ succeeds, and returns the list of values returned by
 -- @p@.  This can be used to scan comments:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.