summaryrefslogtreecommitdiff
path: root/SourceFile.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2021-05-21 09:16:00 +0200
committerTom Smeding <tom@tomsmeding.com>2021-05-21 09:16:00 +0200
commitb03f51f3a363f861f9d5de30ec6a337fec316383 (patch)
treef07e009d6c2b45c188466ab7a52362fe98dcae39 /SourceFile.hs
Initial
Diffstat (limited to 'SourceFile.hs')
-rw-r--r--SourceFile.hs37
1 files changed, 37 insertions, 0 deletions
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"