packages feed

syntax 0.2.0.0 → 0.2.1.0

raw patch · 2 files changed

+51/−24 lines, 2 filesdep ~semi-iso

Dependency ranges changed: semi-iso

Files

Data/Syntax/Combinator.hs view
@@ -1,7 +1,7 @@ {- | Module      :  Data.Syntax.Combinator Description :  Combinators that work with any sequence type.-Copyright   :  (c) Paweł Nowak+Copyright   :  (c) Daan Leijen 1999-2001, Bryan O'Sullivan 2007-2014, Paweł Nowak 2014 License     :  MIT  Maintainer  :  Paweł Nowak <pawel834@gmail.com>@@ -15,16 +15,7 @@ import Control.Lens.SemiIso import Data.SemiIsoFunctor --- | Zero or more occurences of @v@ separated by @s@.-sepBy :: SemiIsoAlternative f => f a -> f () -> f [a]-sepBy v s =  sepBy1 v s -         /|/ sipure _Empty---- | One or more occurences of @v@ separated by @s@.-sepBy1 :: SemiIsoAlternative f => f a -> f () -> f [a]-sepBy1 v s = _Cons /$/ v /*/ (s */ sepBy1 v s /|/ sipure _Empty)---- | One or none occurences of @f@.+-- | One or zero occurences of @f@. optional :: SemiIsoAlternative f => f a -> f (Maybe a) optional f = _Just /$/ f /|/ sipure _Nothing @@ -32,7 +23,30 @@ opt :: SemiIsoAlternative f => f () -> f () opt f = f /|/ sipure id --- | Parser one or more occurences of @f@, but prints nothing.+-- | Parser one or zero occurences of @f@, but prints nothing. opt_ :: SemiIsoAlternative f => f () -> f () opt_ f =  semiIso (const (Left "opt_")) Right /$/ f       /|/ sipure id++-- | @manyTill p end@ applies action p zero or more times until action+-- end succeeds, and returns the list of values returned by p.+manyTill :: SemiIsoAlternative f => f a -> f () -> f [a]+manyTill p end =  _Empty /$/ end+              /|/ _Cons /$/ p /*/ manyTill p end++-- | Zero or more occurences of @v@ separated by @s@.+sepBy :: SemiIsoAlternative f => f a -> f () -> f [a]+sepBy v s = sepBy1 v s /|/ sipure _Empty++-- | One or more occurences of @v@ separated by @s@.+sepBy1 :: SemiIsoAlternative f => f a -> f () -> f [a]+sepBy1 v s = _Cons /$/ v /*/ (s */ sepBy1 v s /|/ sipure _Empty)++-- | Tries to apply the actions in the list in order, until one of+-- them succeeds. Returns the value of the succeeding action.+choice :: SemiIsoAlternative f => [f a] -> f a+choice = foldr (/|/) (sifail "choice: all alternatives failed")++-- | Combine two alternatives.+eitherOf :: SemiIsoAlternative f => f a -> f b -> f (Either a b)+eitherOf a b = _Left /$/ a /|/ _Right /$/ b
syntax.cabal view
@@ -1,15 +1,28 @@ name:                syntax-version:             0.2.0.0-synopsis:            Abstract syntax descriptions for parsing and pretty-printing.-description:         Abstract syntax descriptions for parsing and pretty-printing.-                     Write a single syntax description, get both a parser and a pretty-printer.-                     .-                     Syntax descriptions are based on semi-isomorphisms from @semi-iso@ library.-                     .-                     The library is very young. There are lots of useful combinators that could be written.-                     .-                     See @syntax-example@ for an example, @syntax-attoparsec@ and @syntax-pretty@ for-                     a parser/printer implementation.+version:             0.2.1.0+synopsis:            Syntax descriptions for unified parsing and pretty-printing.+description:+  'syntax' allows you to write a single syntax description and instantiate is both as a parser and a pretty printer.+  .+  The interface is based on a custom Functor/Applicative/Monad hierarchy, provided by the 'semi-iso' package. You fmap using+  a semi-isomorphism instead of function. A semi-isomorphism is a isomorphism that can fail in both directions, with slightly+  weakened laws. It is worth to note that @Iso@s and @Prism@s from 'lens' are valid semi-isomorphisms :)+  .+  Once you write a description you can, for example turn it into an Attoparsec parser.+  .+  See @syntax-example@ for an example, 'syntax-attoparsec' and 'syntax-pretty' for a parser/printer implementation.+  .+  The library was inspired by:+  .+  * Rendel, Tillmann, and Klaus Ostermann. "Invertible syntax descriptions: unifying parsing and pretty printing." ACM Sigplan Notices. Vol. 45. No. 11. ACM, 2010.+  .+  TODO:+  .+  * a printer library based on Text/ByteString builders (wrapping 'pretty' is inefficient and doesn't use any features of it),+  * try to implement indentation and Haskell layout rule,+  * combinators for binary data formats, vectors,+  * implementation of do notation for SemiIsoMonad with QuasiQuoters.+ license:             MIT license-file:        LICENSE author:              Paweł Nowak@@ -27,5 +40,5 @@   exposed-modules:     Data.Syntax                        Data.Syntax.Char                        Data.Syntax.Combinator-  build-depends:       base >= 4 && < 5, mono-traversable, lens >= 4, semi-iso >= 0.4, scientific >= 0.3+  build-depends:       base >= 4 && < 5, mono-traversable, lens >= 4, semi-iso >= 0.4.1, scientific >= 0.3   default-language:    Haskell2010