module TreeSitter ( Language, Node (..), Point (..), extract_comments, tree_sitter_haskell, ) where import Foreign.C.String (CString) import Foreign.C.Types (CInt (..)) import Foreign.Ptr (Ptr) import Foreign.Storable (Storable (..)) data Language data Node = Node { startPoint :: Point, endPoint :: Point, startByte :: CInt, endByte :: CInt } deriving (Show, Eq) instance Storable Node where alignment _ = 8 sizeOf _ = 24 peek ptr = Node <$> peekByteOff ptr 0 <*> peekByteOff ptr 8 <*> peekByteOff ptr 16 <*> peekByteOff ptr 20 poke ptr (Node {..}) = do pokeByteOff ptr 0 startPoint pokeByteOff ptr 8 endPoint pokeByteOff ptr 16 startByte pokeByteOff ptr 20 endByte data Point = Point { row :: CInt, column :: CInt } deriving (Show, Eq) instance Storable Point where alignment _ = 4 sizeOf _ = 8 peek ptr = Point <$> peekByteOff ptr 0 <*> peekByteOff ptr 4 poke ptr (Point {..}) = pokeByteOff ptr 0 row >> pokeByteOff ptr 4 column foreign import ccall unsafe "extract_comments" extract_comments :: Ptr Language -> CString -> Ptr (Ptr Node) -> Ptr CInt -> IO () foreign import ccall unsafe "tree_sitter_haskell" tree_sitter_haskell :: Ptr Language