aboutsummaryrefslogtreecommitdiffstats
path: root/app/Comment
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2023-12-08 06:27:15 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2023-12-08 06:43:01 +0100
commit0d20548e3846cb80acca07fad2a1dc3cfe024528 (patch)
tree6605eb393af99914b4cce483f56e1becbcbe073d /app/Comment
parent5842e730152a2ae11fc8772a505baa3ba81b1e9c (diff)
chore: drop tree-grepper
Regresses in that we only support Haskell for now, as Elm, Nix or Bash are not available as tree-sitter-* Haskell packages.
Diffstat (limited to 'app/Comment')
-rw-r--r--app/Comment/Language.hs39
1 files changed, 39 insertions, 0 deletions
diff --git a/app/Comment/Language.hs b/app/Comment/Language.hs
new file mode 100644
index 0000000..009c6e6
--- /dev/null
+++ b/app/Comment/Language.hs
@@ -0,0 +1,39 @@
+module Comment.Language
+ ( Language (..),
+ fromExtension,
+ parser,
+ lineStart,
+ block,
+ nodeTypes,
+ )
+where
+
+import Control.Exception (throw)
+import Data.Binary (Binary)
+import Data.Text qualified as T
+import Exception qualified as E
+import Foreign.Ptr (Ptr)
+import GHC.Generics (Generic)
+import TreeSitter.Haskell qualified as S
+import TreeSitter.Language qualified as S
+
+data Language
+ = Haskell
+ deriving (Eq, Show, Generic, Binary)
+
+fromExtension :: String -> Language
+fromExtension ".hs" = Haskell
+fromExtension ext = throw $ E.UnknownFileExtension ext
+
+-- TODO add languages elm, shell, nix
+parser :: Language -> Ptr S.Language
+parser Haskell = S.tree_sitter_haskell
+
+lineStart :: Language -> T.Text
+lineStart Haskell = "--"
+
+block :: Language -> Maybe ([T.Text], T.Text)
+block Haskell = Just (["{-"], "-}")
+
+nodeTypes :: Language -> [String]
+nodeTypes Haskell = ["comment"]