packages feed

syntax-pretty (empty) → 0.1.0.0

raw patch · 4 files changed

+99/−0 lines, 4 filesdep +basedep +prettydep +semi-isosetup-changed

Dependencies added: base, pretty, semi-iso, syntax, text

Files

+ Data/Syntax/Pretty.hs view
@@ -0,0 +1,57 @@+{-# LANGUAGE MultiParamTypeClasses #-}+{- |+Module      :  Data.Syntax.Pretty+Description :  Syntax instance for Text.PrettyPrint.+Copyright   :  (c) Paweł Nowak+License     :  MIT++Maintainer  :  Paweł Nowak <pawel834@gmail.com>+Stability   :  experimental++Provides a Syntax instance for Text.PrettyPrint.++-}+module Data.Syntax.Pretty (+    Printer(..)+    ) where++import           Control.Applicative+import           Control.Lens.SemiIso+import           Control.Monad+import           Data.Monoid+import           Data.SemiIsoFunctor+import           Data.Syntax+import           Data.Text (Text)+import qualified Data.Text as T+import qualified Text.PrettyPrint as P++-- | A printer is a function @a -> Either String Doc@.+newtype Printer a = Printer { +    -- | Runs the printer.+    runPrinter :: a -> Either String P.Doc+}++instance SemiIsoFunctor Printer where+    simap ai (Printer f) = Printer (apply ai >=> f)++instance SemiIsoApply Printer where+    sipure _ = Printer (\_ -> Right mempty)+    (Printer f) /*/ (Printer g) = Printer (\(a, b) -> (<>) <$> f a <*> g b)++instance SemiIsoAlternative Printer where+    siempty = Printer (\_ -> Left "error")+    (Printer f) /|/ (Printer g) = Printer (\a -> f a <|> g a)++printText :: Text -> Either String P.Doc+printText = Right . P.text . T.unpack++instance Syntax Printer Text where+   anyChar = Printer (Right . P.char)+   take n = Printer (printText . T.take n)+   takeWhile p = Printer (printText . T.takeWhile p)+   takeWhile1 p = Printer (printText <=< notNull . T.takeWhile p)+     where notNull t | T.null t  = Left "takeWhile1: failed"+                     | otherwise = Right t+   takeTill1 p = Printer (printText <=< notNull . T.takeWhile p)+     where notNull t | T.null t  = Left "takeTill1: failed"+                     | otherwise = Right t
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2014 Paweł Nowak++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ syntax-pretty.cabal view
@@ -0,0 +1,20 @@+name:                syntax-pretty+version:             0.1.0.0+synopsis:            Syntax instance for pretty, the pretty printing library.+license:             MIT+license-file:        LICENSE+author:              Paweł Nowak+maintainer:          Paweł Nowak <pawel834@gmail.com>+copyright:           Paweł Nowak 2014+category:            Data+build-type:          Simple+cabal-version:       >=1.10++source-repository head+  type:     git+  location: git@github.com:Pawel834/syntax-pretty.git++library+  exposed-modules:     Data.Syntax.Pretty+  build-depends:       base >= 4 && < 5, syntax, pretty, semi-iso, text+  default-language:    Haskell2010