Skip to content

Commit f475286

Browse files
authored
Merge branch 'master' into isMissing
2 parents 60508b4 + bf614b3 commit f475286

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

tree-sitter/ChangeLog.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### v0.9.0.4
22

33
* Add `isMissing` flag for nodes.
4+
* Add bindings for the edit API.
45

56
### v0.9.0.3
67

tree-sitter/src/TreeSitter/Node.hs

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ module TreeSitter.Node
99
, FieldId(..)
1010
, ts_node_copy_child_nodes
1111
, ts_node_poke_p
12+
13+
, evalStruct
14+
, peekStruct
15+
, pokeStruct
1216
) where
1317

1418
import Foreign

tree-sitter/src/TreeSitter/Tree.hs

+36
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
{-# LANGUAGE DeriveGeneric #-}
12
module TreeSitter.Tree
23
( Tree
4+
, TSInputEdit(..)
35
, withRootNode
6+
, ts_tree_edit
47
, ts_tree_delete
58
, ts_tree_root_node_p
69
) where
710

811
import Foreign
912
import TreeSitter.Node
13+
import GHC.Generics
1014

1115
-- | This type is uninhabited and used only for type safety within 'Ptr' values.
1216
data Tree
@@ -16,5 +20,37 @@ withRootNode tree action = alloca $ \ ptr -> do
1620
ts_tree_root_node_p tree ptr
1721
action ptr
1822

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 ()
1955
foreign import ccall safe "ts_tree_delete" ts_tree_delete :: Ptr Tree -> IO ()
2056
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

Comments
 (0)