packages feed

syntax-pretty 0.1.0.1 → 0.2.0.0

raw patch · 2 files changed

+24/−11 lines, 2 filesdep +scientificdep ~semi-isodep ~syntax

Dependencies added: scientific

Dependency ranges changed: semi-iso, syntax

Files

Data/Syntax/Pretty.hs view
@@ -21,6 +21,7 @@ import           Data.Monoid import           Data.SemiIsoFunctor import           Data.Syntax+import           Data.Syntax.Char import           Data.Text (Text) import qualified Data.Text as T import qualified Text.PrettyPrint as P@@ -42,16 +43,28 @@     siempty = Printer (\_ -> Left "error")     (Printer f) /|/ (Printer g) = Printer (\a -> f a <|> g a) +instance SemiIsoMonad Printer where+    (Printer f) //= g = Printer (\(a, b) -> (<>) <$> f a <*> runPrinter (g a) b)++instance SemiIsoFix Printer where+    sifix f = Printer $ \a -> runPrinter (f a) 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+    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++instance SyntaxChar Printer Text where+    decimal = Printer (format . toInteger)+      where format i | i < 0 = Left "decimal: negative number"+                     | otherwise = Right (P.integer i)+    scientific = Printer (Right . P.text . show)
syntax-pretty.cabal view
@@ -1,5 +1,5 @@ name:                syntax-pretty-version:             0.1.0.1+version:             0.2.0.0 synopsis:            Syntax instance for pretty, the pretty printing library. license:             MIT license-file:        LICENSE@@ -16,5 +16,5 @@  library   exposed-modules:     Data.Syntax.Pretty-  build-depends:       base >= 4 && < 5, syntax, pretty, semi-iso, text+  build-depends:       base >= 4 && < 5, syntax >= 0.2, pretty, semi-iso >= 0.3, text, scientific >= 0.3   default-language:    Haskell2010