aboutsummaryrefslogtreecommitdiffstats
path: root/app/Comment
diff options
context:
space:
mode:
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"]