on master help sign in
Added some combinators.
commit156a969caa94e990b76444154eb0a6bc91a57fab authorPaweł Nowak <pawel834@gmail.com> dateThu 30 Oct 2014, 16:38 (12 years ago) parent558eb65
2 files changed+27−1
Data/Syntax/Combinator.hs+25 syntax.cabal+2−1
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 @@
11name: syntax
2−version: 0.1.0.0
2+version: 0.1.1.0
33synopsis: Abstract syntax descriptions for parsing and pretty-printing.
44description: Write single syntax description, get both parser and pretty-printer.
55 .
@@ -24,5 +24,6 @@ source-repository head
2424library
2525 exposed-modules: Data.Syntax
2626 Data.Syntax.Char
27+ Data.Syntax.Combinator
2728 build-depends: base >= 4 && < 5, mono-traversable, lens, semi-iso
2829 default-language: Haskell2010