on master help sign in
Data/Syntax.hs+4
since splitsnapshots
unifiedsplit
@@ -166,6 +166,10 @@ instance Syntax syn => Syntax (ReaderCT env syn) where
166 takeWhile1 = clift . takeWhile1
166 takeWhile1 = clift . takeWhile1
167 takeTill = clift . takeTill
167 takeTill = clift . takeTill
168 takeTill1 = clift . takeTill1
168 takeTill1 = clift . takeTill1
169+ vecN n e = ReaderCT $ vecN n . runReaderCT e
170+ ivecN n e = ReaderCT $ ivecN n . runReaderCT e
171+ uvecN n e = ReaderCT $ uvecN n . runReaderCT e
172+ uivecN n e = ReaderCT $ uivecN n . runReaderCT e
169
173
170-- | Execute a computation in an isolated context.
174-- | Execute a computation in an isolated context.
171--
175--
Data/Syntax/Combinator.hs+10−1
@@ -26,6 +26,9 @@ module Data.Syntax.Combinator
26 sepBy,
26 sepBy,
27 sepBy1,
27 sepBy1,
28
28
29+ -- * Arrowized combinators.
30+ takeArr,
31+
29 -- * Vectors.
32 -- * Vectors.
30 vecNSepBy,
33 vecNSepBy,
31 ivecNSepBy,
34 ivecNSepBy,
@@ -48,10 +51,11 @@ import Control.Category.Structures
48import Control.Lens
51import Control.Lens
49import Control.Lens.SemiIso
52import Control.Lens.SemiIso
50import Control.SIArrow
53import Control.SIArrow
54+import qualified Data.MonoTraversable as Seq
51import Data.Syntax
55import Data.Syntax
52import qualified Data.Vector as V
56import qualified Data.Vector as V
53import qualified Data.Vector.Unboxed as VU
57import qualified Data.Vector.Unboxed as VU
54−import Prelude hiding (id, (.))
58+import Prelude hiding (id, (.), take)
55
59
56-- | One or zero occurences of @f@.
60-- | One or zero occurences of @f@.
57optional :: SIArrow cat => cat () a -> cat () (Maybe a)
61optional :: SIArrow cat => cat () a -> cat () (Maybe a)
@@ -89,6 +93,11 @@ sepBy v s = sepBy1 v s /+/ sipure _Empty
89sepBy1 :: SIArrow cat => cat () a -> cat () () -> cat () [a]
93sepBy1 :: SIArrow cat => cat () a -> cat () () -> cat () [a]
90sepBy1 v s = _Cons /$/ v /*/ (s */ sepBy1 v s /+/ sipure _Empty)
94sepBy1 v s = _Cons /$/ v /*/ (s */ sepBy1 v s /+/ sipure _Empty)
91
95
96+-- | A string of given length.
97+takeArr :: Syntax syn => syn Int (Seq syn)
98+takeArr = sibind $ iso (\n -> constant n #>> take n)
99+ (\s -> constant (Seq.olength s) #>> take (Seq.olength s))
100+
92-- | Constant size vector with separators.
101-- | Constant size vector with separators.
93--
102--
94-- @vecNSepBy n e sep@ describes a size @n@ vector with elements @e@ separated by @sep@.
103-- @vecNSepBy n e sep@ describes a size @n@ vector with elements @e@ separated by @sep@.
syntax.cabal+1−1
@@ -22,7 +22,7 @@ description:
22 a reader category transformer that tracks current indentation level. I plan on implementing Haskell layout rule in the
22 a reader category transformer that tracks current indentation level. I plan on implementing Haskell layout rule in the
23 future.
23 future.
24 .
24 .
25− Note that the library can work with both text and binary data. Alas, there are no binary combinators implemented yet.
25+ The library can work with both text and binary data. Alas, there are no binary combinators implemented yet.
26 I will implement them when i have the time (but these category transformers look so much more interesting for now ;).
26 I will implement them when i have the time (but these category transformers look so much more interesting for now ;).
27 .
27 .
28 EXAMPLES! See @syntax-example@ and @syntax-example-json@ for examples.
28 EXAMPLES! See @syntax-example@ and @syntax-example-json@ for examples.