1 module Language.Symantic.Document.Plain where
3 import Control.Monad (Monad(..), replicateM_)
4 import Data.Function (($), (.), id)
5 import Data.Monoid (Monoid(..))
6 import Data.Semigroup (Semigroup(..))
7 import Data.String (IsString(..))
9 import Text.Show (Show(..))
10 import qualified Data.Text.IO as T
11 import qualified Data.Text.Lazy as TL
12 import qualified Data.Text.Lazy.IO as TL
13 import qualified Data.Text.Lazy.Builder as TLB
14 import qualified System.IO as IO
16 import Language.Symantic.Document.Sym
22 instance IsString Plain where
23 fromString = Plain . fromString
25 plain :: Plain -> TLB.Builder
28 instance Semigroup Plain where
29 Plain x <> Plain y = Plain (x <> y)
30 instance Monoid Plain where
33 instance Doc_Text Plain where
34 int = Plain . fromString . show
35 integer = Plain . fromString . show
36 replicate i = Plain . TLB.fromLazyText . TL.replicate (int64OfInt i) . TLB.toLazyText . plain
37 char = Plain . TLB.singleton
38 string = Plain . fromString
39 text = Plain . TLB.fromText
40 ltext = Plain . TLB.fromLazyText
45 instance Doc_Color Plain where
79 instance Doc_Decoration Plain where
86 = PlainIO { unPlainH :: IO.Handle -> IO () }
87 instance IsString PlainIO where
88 fromString s = PlainIO $ \h -> IO.hPutStr h t
89 where t = fromString s
91 plainIO :: PlainIO -> IO.Handle -> IO ()
92 plainIO (PlainIO d) = d
94 instance Semigroup PlainIO where
95 PlainIO x <> PlainIO y = PlainIO $ \h -> do {x h; y h}
96 instance Monoid PlainIO where
99 instance Doc_Text PlainIO where
100 empty = PlainIO $ \_ -> return ()
101 int i = PlainIO $ \h -> IO.hPutStr h (show i)
102 integer i = PlainIO $ \h -> IO.hPutStr h (show i)
103 replicate i d = PlainIO $ replicateM_ i . plainIO d
104 char x = PlainIO $ \h -> IO.hPutChar h x
105 string x = PlainIO $ \h -> IO.hPutStr h x
106 text x = PlainIO $ \h -> T.hPutStr h x
107 ltext x = PlainIO $ \h -> TL.hPutStr h x
112 instance Doc_Color PlainIO where
146 instance Doc_Decoration PlainIO where