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
29 instance Semigroup Plain where
30 Plain x <> Plain y = Plain (x <> y)
31 instance Monoid Plain where
34 instance Doc_Text Plain where
35 int = Plain . fromString . show
36 integer = Plain . fromString . show
37 replicate i = Plain . TLB.fromLazyText . TL.replicate (int64OfInt i) . TLB.toLazyText . plain
38 char = Plain . TLB.singleton
39 string = Plain . fromString
40 text = Plain . TLB.fromText
41 ltext = Plain . TLB.fromLazyText
46 instance Doc_Color Plain where
80 instance Doc_Decoration Plain where
87 = PlainIO { unPlainH :: IO.Handle -> IO () }
88 instance IsString PlainIO where
89 fromString s = PlainIO $ \h -> IO.hPutStr h t
90 where t = fromString s
92 plainIO :: PlainIO -> IO.Handle -> IO ()
93 plainIO (PlainIO d) = d
95 instance Semigroup PlainIO where
96 PlainIO x <> PlainIO y = PlainIO $ \h -> do {x h; y h}
97 instance Monoid PlainIO where
100 instance Doc_Text PlainIO where
101 empty = PlainIO $ \_ -> return ()
102 int i = PlainIO $ \h -> IO.hPutStr h (show i)
103 integer i = PlainIO $ \h -> IO.hPutStr h (show i)
104 replicate i d = PlainIO $ replicateM_ i . plainIO d
105 char x = PlainIO $ \h -> IO.hPutChar h x
106 string x = PlainIO $ \h -> IO.hPutStr h x
107 text x = PlainIO $ \h -> T.hPutStr h x
108 ltext x = PlainIO $ \h -> TL.hPutStr h x
113 instance Doc_Color PlainIO where
147 instance Doc_Decoration PlainIO where