Copyright | (c) Paweł Nowak |
---|---|
License | MIT |
Maintainer | Paweł Nowak <pawel834@gmail.com> |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Reversible parsing and pretty-printing.
- class (SIArrow syn, IsSequence (Seq syn), Eq (Seq syn), Eq (Element (Seq syn))) => Syntax syn where
- type Seq syn :: *
- anyChar :: syn () (Element (Seq syn))
- char :: Element (Seq syn) -> syn () ()
- notChar :: Element (Seq syn) -> syn () (Element (Seq syn))
- satisfy :: (Element (Seq syn) -> Bool) -> syn () (Element (Seq syn))
- satisfyWith :: ASemiIso' a (Element (Seq syn)) -> (a -> Bool) -> syn () a
- string :: Seq syn -> syn () ()
- take :: Int -> syn () (Seq syn)
- takeWhile :: (Element (Seq syn) -> Bool) -> syn () (Seq syn)
- takeWhile1 :: (Element (Seq syn) -> Bool) -> syn () (Seq syn)
- takeTill :: (Element (Seq syn) -> Bool) -> syn () (Seq syn)
- takeTill1 :: (Element (Seq syn) -> Bool) -> syn () (Seq syn)
- vecN :: Int -> syn () a -> syn () (Vector a)
- ivecN :: Int -> syn Int (Int, a) -> syn () (Vector a)
- uvecN :: Unbox a => Int -> syn () a -> syn () (Vector a)
- uivecN :: Unbox a => Int -> syn Int (Int, a) -> syn () (Vector a)
- class Syntax syn => Isolable syn where
- packed :: IsSequence seq => Iso' seq [Element seq]
Syntax.
class (SIArrow syn, IsSequence (Seq syn), Eq (Seq syn), Eq (Element (Seq syn))) => Syntax syn where Source
An abstract syntax description based on semi-isomorphisms.
This class can be implemented by both parsers and printers.
The usual use is to write a polymorphic syntax description and instantiate it both as a parser and a printer. Examples are available in 'syntax-example' and 'syntax-example-json' packages.
Methods of this class try to mimic Data.Attoparsec.Text interface.
anyChar :: syn () (Element (Seq syn)) Source
Any character.
char :: Element (Seq syn) -> syn () () Source
A specific character.
notChar :: Element (Seq syn) -> syn () (Element (Seq syn)) Source
Any character except the given one.
satisfy :: (Element (Seq syn) -> Bool) -> syn () (Element (Seq syn)) Source
Any character satisfying a predicate.
satisfyWith :: ASemiIso' a (Element (Seq syn)) -> (a -> Bool) -> syn () a Source
Transforms a character using a SemiIso and filters out values not satisfying the predicate.
string :: Seq syn -> syn () () Source
A specific string.
take :: Int -> syn () (Seq syn) Source
A string of length n
.
takeWhile :: (Element (Seq syn) -> Bool) -> syn () (Seq syn) Source
Maximal string which elements satisfy a predicate.
takeWhile1 :: (Element (Seq syn) -> Bool) -> syn () (Seq syn) Source
Maximal non-empty string which elements satisfy a predicate.
takeTill :: (Element (Seq syn) -> Bool) -> syn () (Seq syn) Source
Maximal string which elements do not satisfy a predicate.
takeTill1 :: (Element (Seq syn) -> Bool) -> syn () (Seq syn) Source
Maximal non-empty string which elements do not satisfy a predicate.
vecN :: Int -> syn () a -> syn () (Vector a) Source
Constant size vector. The default implementation uses lists, but "syntax-attoparsec" and "syntax-printer" override it with an efficient implementation that works on a vector directly.
vecN n e
describes a size n
vector with elements e
.
Also see vec
.
ivecN :: Int -> syn Int (Int, a) -> syn () (Vector a) Source
Constant size vector with index-aware element. The default implementation uses lists, but "syntax-attoparsec" and "syntax-printer" override it with an efficient implementation that works on a vector directly.
ivecN n e
describes a size n
vector with elements e
. Each element
gets its index and should output a value and the index unchanged.
Also see ivec
.
uvecN :: Unbox a => Int -> syn () a -> syn () (Vector a) Source
Constant size unboxed vector. The default implementation uses lists, but "syntax-attoparsec" and "syntax-printer" override it with an efficient implementation that works on a vector directly.
vecN n e
describes a size n
vector with elements e
.
Also see vec
.
uivecN :: Unbox a => Int -> syn Int (Int, a) -> syn () (Vector a) Source
Constant size unboxed vector with index-aware element. The default implementation uses lists, but "syntax-attoparsec" and "syntax-printer" override it with an efficient implementation that works on a vector directly.
ivecN n e
describes a size n
vector with elements e
. Each element
gets its index and should output a value and the index unchanged.
Also see ivec
.
class Syntax syn => Isolable syn where Source
Execute a computation in an isolated context.
The motivating example: you want to write a function
serializeList :: Syntax syn => syn () a -> syn () [a]
Notice that we cannot just use simany, because the first syn () a
could eat the entire sequence (even though we printed more than 1 value!), so
we have to insert some kind of separators between the element. But how can we
be sure that syn () a
will not eat our separators? We can't! Thats why we
have to do the parsing in two stages: first extract the sequence between separators,
then run the syn () a
on this sequence.
Common isomorphisms.
packed :: IsSequence seq => Iso' seq [Element seq] Source
An isomorphism between a sequence and a list of its elements.