Skip to content

Commit

Permalink
Add isMissing flag (#320)
Browse files Browse the repository at this point in the history
* add isMissing flag

* fix tests

* update changelog

---------

Co-authored-by: Madeleine Sydney <[email protected]>
  • Loading branch information
crumb and msyds authored Sep 23, 2024
1 parent bf614b3 commit b76872e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions tree-sitter/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### v0.9.0.4

* Add `isMissing` flag for nodes.
* Add bindings for the edit API.

### v0.9.0.3
Expand Down
5 changes: 4 additions & 1 deletion tree-sitter/src/TreeSitter/Node.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ data Node = Node
, nodeFieldName :: !CString
, nodeIsNamed :: !CBool
, nodeIsExtra :: !CBool
, nodeIsMissing :: !CBool
}
deriving (Show, Eq, Generic)

Expand Down Expand Up @@ -85,8 +86,9 @@ instance Storable Node where
<*> peekStruct
<*> peekStruct
<*> peekStruct
<*> peekStruct
{-# INLINE peek #-}
poke ptr (Node n t s ep eb c fn nn ne) = flip evalStruct ptr $ do
poke ptr (Node n t s ep eb c fn nn ne nm) = flip evalStruct ptr $ do
pokeStruct n
pokeStruct t
pokeStruct s
Expand All @@ -96,6 +98,7 @@ instance Storable Node where
pokeStruct fn
pokeStruct nn
pokeStruct ne
pokeStruct nm
{-# INLINE poke #-}

instance Storable TSPoint where
Expand Down
2 changes: 2 additions & 0 deletions tree-sitter/src/bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ typedef struct Node {
const char *fieldName;
bool isNamed;
bool isExtra;
bool isMissing;
} Node;

void log_to_stdout(void *payload, TSLogType type, const char *message) {
Expand All @@ -33,6 +34,7 @@ static inline void ts_node_poke(const char *fieldName, TSNode node, Node *out) {
out->fieldName = fieldName;
out->isNamed = ts_node_is_named(node);
out->isExtra = ts_node_is_extra(node);
out->isMissing = ts_node_is_missing(node);
}

void ts_node_poke_p(TSNode *node, Node *out) {
Expand Down
4 changes: 2 additions & 2 deletions tree-sitter/test/TreeSitter/Example.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ prop_Node_sizeOf = property $
sizeOf (undefined :: Node) === fromIntegral sizeof_node

prop_Node_roundtrips = property $ do
peeked <- liftIO (with (Node (TSNode 1 (TSPoint 2 3) 4 nullPtr nullPtr) nullPtr 1 (TSPoint 4 5) 7 8 nullPtr 9 10) peek)
peeked === Node (TSNode 1 (TSPoint 2 3) 4 nullPtr nullPtr) nullPtr 1 (TSPoint 4 5) 7 8 nullPtr 9 10
peeked <- liftIO (with (Node (TSNode 1 (TSPoint 2 3) 4 nullPtr nullPtr) nullPtr 1 (TSPoint 4 5) 7 8 nullPtr 9 10 11) peek)
peeked === Node (TSNode 1 (TSPoint 2 3) 4 nullPtr nullPtr) nullPtr 1 (TSPoint 4 5) 7 8 nullPtr 9 10 11

prop_TSTreeCursor_sizeOf = property $
sizeOfCursor === fromIntegral sizeof_tstreecursor
Expand Down

0 comments on commit b76872e

Please sign in to comment.