blob: 0a054c0334ff75882d9c7d1e40442a27c1794a43 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
module SourceFile where
import qualified Data.Text.Lazy.Builder as B
import Data.Text.Lazy.Builder (Builder)
import Data.Text.Lazy (Text)
import Pretty
data SourceFile = SourceFile [Chunk]
deriving (Show)
data Chunk = CSkip Text
| COcc Occurrence
deriving (Show)
data Occurrence = Occurrence
{ occName :: Text
, occArgs :: [(Text, Text)] } -- prefix spacing, argument value
deriving (Show)
instance Pretty SourceFile where
pretty' (SourceFile cs) = mconcat (map pretty' cs)
instance Pretty Chunk where
pretty' (CSkip s) = B.fromLazyText s
pretty' (COcc occ) = pretty' occ
instance Pretty Occurrence where
pretty' (Occurrence name args) =
ansiBG '1' (B.fromLazyText name)
<> mconcat [ansiBG '4' (B.fromLazyText pre)
<> ansiBG '3' (B.fromLazyText val)
| (pre, val) <- args]
where
ansiBG :: Char -> Builder -> Builder
ansiBG c b = B.fromString ("\x1B[1;4" ++ c : "m") <> b <> B.fromString "\x1B[0m"
|