1 module Language.Symantic.Document.Plain where
3 import Control.Monad (Monad(..))
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.List as L
11 import qualified Data.Text as T
12 import qualified Data.Text.IO as T
13 import qualified Data.Text.Lazy.IO as TL
14 import qualified Data.Text.Lazy.Builder as TLB
15 import qualified System.IO as IO
17 import Language.Symantic.Document.Sym
23 instance IsString Plain where
24 fromString = Plain . fromString
26 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 spaces i = Plain $ TLB.fromText $ T.replicate i " "
36 int = Plain . fromString . show
37 integer = Plain . fromString . show
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 spaces i = PlainIO $ \h -> IO.hPutStr h (L.replicate i ' ')
103 int i = PlainIO $ \h -> IO.hPutStr h (show i)
104 integer i = PlainIO $ \h -> IO.hPutStr h (show i)
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