on master help sign in
Added some combinators.
156a969Paweł Nowak
Data/Syntax/Combinator.hsnew file+25
@@ -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)
syntax.cabal+2−1
@@ -1,5 +1,5 @@
1name: syntax
1name: syntax
2−version: 0.1.0.0
2+version: 0.1.1.0
3synopsis: Abstract syntax descriptions for parsing and pretty-printing.
3synopsis: Abstract syntax descriptions for parsing and pretty-printing.
4description: Write single syntax description, get both parser and pretty-printer.
4description: Write single syntax description, get both parser and pretty-printer.
5 .
5 .
@@ -24,5 +24,6 @@ source-repository head
24library
24library
25 exposed-modules: Data.Syntax
25 exposed-modules: Data.Syntax
26 Data.Syntax.Char
26 Data.Syntax.Char
27+ Data.Syntax.Combinator
27 build-depends: base >= 4 && < 5, mono-traversable, lens, semi-iso
28 build-depends: base >= 4 && < 5, mono-traversable, lens, semi-iso
28 default-language: Haskell2010
29 default-language: Haskell2010