aboutsummaryrefslogtreecommitdiffstats
path: root/app/Comment/Language.hs
blob: 67c3413584894d5b258092b91287623c2a1110b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
--
-- @supersedes add-support-for-all-tree-grepper-supported-files
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"]