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"