1
+ {-# LANGUAGE DeriveGeneric #-}
1
2
module TreeSitter.Tree
2
3
( Tree
4
+ , TSInputEdit (.. )
3
5
, withRootNode
6
+ , ts_tree_edit
4
7
, ts_tree_delete
5
8
, ts_tree_root_node_p
6
9
) where
7
10
8
11
import Foreign
9
12
import TreeSitter.Node
13
+ import GHC.Generics
10
14
11
15
-- | This type is uninhabited and used only for type safety within 'Ptr' values.
12
16
data Tree
@@ -16,5 +20,37 @@ withRootNode tree action = alloca $ \ ptr -> do
16
20
ts_tree_root_node_p tree ptr
17
21
action ptr
18
22
23
+ -- | Locational info used for to adjust the source ranges of a 'Tree'\'s nodes.
24
+ -- This record dirrectly corresponds to the C struct of the same name.
25
+ data TSInputEdit = TSInputEdit
26
+ { start_byte :: ! Word32
27
+ , old_end_byte :: ! Word32
28
+ , new_end_byte :: ! Word32
29
+ , start_point :: ! TSPoint
30
+ , old_end_point :: ! TSPoint
31
+ , new_end_point :: ! TSPoint
32
+ }
33
+ deriving (Show , Eq , Generic )
34
+
35
+ instance Storable TSInputEdit where
36
+ alignment _ = alignment (0 :: Int32 )
37
+ sizeOf _ = 36
38
+ peek = evalStruct $
39
+ TSInputEdit <$> peekStruct
40
+ <*> peekStruct
41
+ <*> peekStruct
42
+ <*> peekStruct
43
+ <*> peekStruct
44
+ <*> peekStruct
45
+ poke ptr (TSInputEdit sb oldEb newEb sp oldEp newEp) =
46
+ flip evalStruct ptr $ do
47
+ pokeStruct sb
48
+ pokeStruct oldEb
49
+ pokeStruct newEb
50
+ pokeStruct sp
51
+ pokeStruct oldEp
52
+ pokeStruct newEp
53
+
54
+ foreign import ccall safe " ts_tree_edit" ts_tree_edit :: Ptr Tree -> Ptr TSInputEdit -> IO ()
19
55
foreign import ccall safe " ts_tree_delete" ts_tree_delete :: Ptr Tree -> IO ()
20
56
foreign import ccall unsafe " src/bridge.c ts_tree_root_node_p" ts_tree_root_node_p :: Ptr Tree -> Ptr Node -> IO ()
0 commit comments