diff options
author | Alexander Foremny <aforemny@posteo.de> | 2023-10-04 10:01:50 +0200 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2023-10-04 10:01:50 +0200 |
commit | 4adb99e683b81df9d572c05db06e6fb688fb007a (patch) | |
tree | 84be7f1aa0bf83e272cf600c0ae4c2bc0b51af21 /app/TreeGrepper/FileType.hs | |
parent | 3ae98347e7ad3e410974c4f6bac1ccaf56daa280 (diff) |
bring issue extraction on-par with shell script
Diffstat (limited to 'app/TreeGrepper/FileType.hs')
-rw-r--r-- | app/TreeGrepper/FileType.hs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/app/TreeGrepper/FileType.hs b/app/TreeGrepper/FileType.hs new file mode 100644 index 0000000..843eaf1 --- /dev/null +++ b/app/TreeGrepper/FileType.hs @@ -0,0 +1,76 @@ +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE OverloadedStrings #-} + +module TreeGrepper.FileType + ( FileType (..), + all, + Info (..), + BlockInfo (..), + info, + ) +where + +import Data.Aeson (FromJSON (parseJSON)) +import Data.Text (Text) +import Prelude hiding (all) + +data FileType + = Elm + | Haskell + | Nix + | Shell + deriving (Show) + +instance FromJSON FileType where + parseJSON v = + parseJSON v >>= \case + "elm" -> pure Elm + "haskell" -> pure Haskell + "nix" -> pure Nix + "sh" -> pure Shell + fileType -> fail ("parsing file_type failed, got " ++ fileType) + +all :: [FileType] +all = + [ Elm, + Haskell, + Nix, + Shell + ] + +data Info = Info + { exts :: [String], + lineStart :: Text, + block :: Maybe BlockInfo + } + +data BlockInfo = BlockInfo + { blockStart :: [Text], + blockEnd :: Text + } + +info :: FileType -> Info +info Elm = + Info + { exts = [".elm"], + lineStart = "--", + block = Just BlockInfo {blockStart = ["{-|", "{-"], blockEnd = "-}"} + } +info Haskell = + Info + { exts = [".hs"], + lineStart = "--", + block = Just BlockInfo {blockStart = ["{-"], blockEnd = "-}"} + } +info Nix = + Info + { exts = [".nix"], + lineStart = "#", + block = Just BlockInfo {blockStart = ["/*"], blockEnd = "*/"} + } +info Shell = + Info + { exts = [".sh"], + lineStart = "#", + block = Nothing + } |