From b03f51f3a363f861f9d5de30ec6a337fec316383 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Fri, 21 May 2021 09:16:00 +0200 Subject: Initial --- SourceFile.hs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 SourceFile.hs (limited to 'SourceFile.hs') diff --git a/SourceFile.hs b/SourceFile.hs new file mode 100644 index 0000000..0a054c0 --- /dev/null +++ b/SourceFile.hs @@ -0,0 +1,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" -- cgit v1.2.3-70-g09d2