on 501ca35 help sign in
Data/Syntax.hs−4
since splitsnapshots
unifiedsplit
@@ -166,10 +166,6 @@ 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
173
169
174-- | Execute a computation in an isolated context.
170-- | Execute a computation in an isolated context.
175--
171--
Data/Syntax/Combinator.hs+1−10
@@ -26,9 +26,6 @@ module Data.Syntax.Combinator
26 sepBy,
26 sepBy,
27 sepBy1,
27 sepBy1,
28
28
29− -- * Arrowized combinators.
30− takeArr,
31−
32 -- * Vectors.
29 -- * Vectors.
33 vecNSepBy,
30 vecNSepBy,
34 ivecNSepBy,
31 ivecNSepBy,
@@ -51,11 +48,10 @@ import Control.Category.Structures
51import Control.Lens
48import Control.Lens
52import Control.Lens.SemiIso
49import Control.Lens.SemiIso
53import Control.SIArrow
50import Control.SIArrow
54−import qualified Data.MonoTraversable as Seq
55import Data.Syntax
51import Data.Syntax
56import qualified Data.Vector as V
52import qualified Data.Vector as V
57import qualified Data.Vector.Unboxed as VU
53import qualified Data.Vector.Unboxed as VU
58−import Prelude hiding (id, (.), take)
54+import Prelude hiding (id, (.))
59
55
60-- | One or zero occurences of @f@.
56-- | One or zero occurences of @f@.
61optional :: SIArrow cat => cat () a -> cat () (Maybe a)
57optional :: SIArrow cat => cat () a -> cat () (Maybe a)
@@ -93,11 +89,6 @@ sepBy v s = sepBy1 v s /+/ sipure _Empty
93sepBy1 :: SIArrow cat => cat () a -> cat () () -> cat () [a]
89sepBy1 :: SIArrow cat => cat () a -> cat () () -> cat () [a]
94sepBy1 v s = _Cons /$/ v /*/ (s */ sepBy1 v s /+/ sipure _Empty)
90sepBy1 v s = _Cons /$/ v /*/ (s */ sepBy1 v s /+/ sipure _Empty)
95
91
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−
101-- | Constant size vector with separators.
92-- | Constant size vector with separators.
102--
93--
103-- @vecNSepBy n e sep@ describes a size @n@ vector with elements @e@ separated by @sep@.
94-- @vecNSepBy n e sep@ describes a size @n@ vector with elements @e@ separated by @sep@.
syntax.cabal+7−7
@@ -4,10 +4,9 @@ synopsis: Reversible parsing and pretty-printing.
4description:
4description:
5 "syntax" allows you to write a single syntax description and instantiate is both as a parser and a pretty printer.
5 "syntax" allows you to write a single syntax description and instantiate is both as a parser and a pretty printer.
6 .
6 .
7− Syntax descriptions are written in applicative or arrow style. The library uses a custom typeclass hierarchy, provided
7+ Syntax descriptions are written in applicative or arrow style. The library uses a custom hierarchy, provided by the
8− by the "semi-iso" package. Most of the time you will be using operators like '/$/', '/*/' and '/+/' (= '<|>'), just
8+ "semi-iso" package. Most of the time you will be using operators like '/$/' and '/*/', just like parser combinators.
9− like parser combinators. When more power is needed - e.g. when the syntax depends on the parsed or printed value -
9+ When more power is needed - e.g. when the syntax depends on the parsed or printed value - you turn to arrows.
10− you turn to arrows.
11 .
10 .
12 Semi-isomorphisms from "semi-iso" are the basic building block of syntax descriptions. I recommend reading
11 Semi-isomorphisms from "semi-iso" are the basic building block of syntax descriptions. I recommend reading
13 the hackage page of "semi-iso" first, as it contains much more information.
12 the hackage page of "semi-iso" first, as it contains much more information.
@@ -20,10 +19,11 @@ description:
20 Advanced formatting and parsing (for example indentation, haskell layout rule) is implemented as category transformers
19 Advanced formatting and parsing (for example indentation, haskell layout rule) is implemented as category transformers
21 (similar to monad transformers). Currently only simple indentation is implemented (in "Data.Syntax.Indent") - basically
20 (similar to monad transformers). Currently only simple indentation is implemented (in "Data.Syntax.Indent") - basically
22 a reader category transformer that tracks current indentation level. I plan on implementing Haskell layout rule in the
21 a reader category transformer that tracks current indentation level. I plan on implementing Haskell layout rule in the
23− future.
22+ future (as a reusable transformer).
24 .
23 .
25− The library can work with both text and binary data. Alas, there are no binary combinators implemented yet.
24+ Note that the library can work with both text and binary data. There are no binary combinators implemented - yet.
25+ Alas, these are not only useful combinators missing! I will slowly but steadily implement them over time
26− I will implement them when i have the time (but these category transformers look so much more interesting for now ;).
26+ (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.
29 .
29 .