@@ -0,0 +1,25 @@
1+{- |
2+Module : Data.Syntax.Combinator
3+Description : Combinators that work with any sequence type.
4+Copyright : (c) Paweł Nowak
5+License : MIT
6+
7+Maintainer : Paweł Nowak <pawel834@gmail.com>
8+Stability : experimental
9+
10+Combinators that work with any sequence type.
11+-}
12+module Data.Syntax.Combinator where
13+
14+import Control.Lens.Cons
15+import Control.Lens.Empty
16+import Data.SemiIsoFunctor
17+
18+-- | Zero or more occurences of v separated by s.
19+sepBy :: SemiIsoAlternative f => f a -> f () -> f [a]
20+sepBy v s = sepBy1 v s
21+ /|/ sipure _Empty
22+
23+-- | One or more occurences of v separated by s.
24+sepBy1 :: SemiIsoAlternative f => f a -> f () -> f [a]
25+sepBy1 v s = _Cons /$/ v /*/ (s */ sepBy1 v s /|/ sipure _Empty)