{-# LANGUAGE DeriveGeneric, GeneralizedNewtypeDeriving, RankNTypes, ScopedTypeVariables #-}
{-# OPTIONS_GHC -funbox-strict-fields #-}
module TreeSitter.Node
( Node(..)
, nodeStartPoint
, nodeStartByte
, TSPoint(..)
, TSNode(..)
, FieldId(..)
, ts_node_copy_child_nodes
, ts_node_poke_p
) where
import Foreign
import Foreign.C
import GHC.Generics
import TreeSitter.Symbol (TSSymbol)
data Node = Node
{ Node -> TSNode
nodeTSNode :: !TSNode
, Node -> CString
nodeType :: !CString
, Node -> TSSymbol
nodeSymbol :: !TSSymbol
, Node -> TSPoint
nodeEndPoint :: !TSPoint
, Node -> Word32
nodeEndByte :: !Word32
, Node -> Word32
nodeChildCount :: !Word32
, Node -> CString
nodeFieldName :: !CString
, Node -> CBool
nodeIsNamed :: !CBool
, :: !CBool
}
deriving (Int -> Node -> ShowS
[Node] -> ShowS
Node -> String
(Int -> Node -> ShowS)
-> (Node -> String) -> ([Node] -> ShowS) -> Show Node
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Node] -> ShowS
$cshowList :: [Node] -> ShowS
show :: Node -> String
$cshow :: Node -> String
showsPrec :: Int -> Node -> ShowS
$cshowsPrec :: Int -> Node -> ShowS
Show, Node -> Node -> Bool
(Node -> Node -> Bool) -> (Node -> Node -> Bool) -> Eq Node
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Node -> Node -> Bool
$c/= :: Node -> Node -> Bool
== :: Node -> Node -> Bool
$c== :: Node -> Node -> Bool
Eq, (forall x. Node -> Rep Node x)
-> (forall x. Rep Node x -> Node) -> Generic Node
forall x. Rep Node x -> Node
forall x. Node -> Rep Node x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Node x -> Node
$cfrom :: forall x. Node -> Rep Node x
Generic)
nodeStartPoint :: Node -> TSPoint
nodeStartPoint :: Node -> TSPoint
nodeStartPoint Node
node = let TSNode Word32
_ TSPoint
p Word32
_ Ptr ()
_ Ptr ()
_ = Node -> TSNode
nodeTSNode Node
node in TSPoint
p
nodeStartByte :: Node -> Word32
nodeStartByte :: Node -> Word32
nodeStartByte Node
node = let TSNode Word32
b TSPoint
_ Word32
_ Ptr ()
_ Ptr ()
_ = Node -> TSNode
nodeTSNode Node
node in Word32
b
data TSPoint = TSPoint { TSPoint -> Word32
pointRow :: !Word32, TSPoint -> Word32
pointColumn :: !Word32 }
deriving (Int -> TSPoint -> ShowS
[TSPoint] -> ShowS
TSPoint -> String
(Int -> TSPoint -> ShowS)
-> (TSPoint -> String) -> ([TSPoint] -> ShowS) -> Show TSPoint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TSPoint] -> ShowS
$cshowList :: [TSPoint] -> ShowS
show :: TSPoint -> String
$cshow :: TSPoint -> String
showsPrec :: Int -> TSPoint -> ShowS
$cshowsPrec :: Int -> TSPoint -> ShowS
Show, TSPoint -> TSPoint -> Bool
(TSPoint -> TSPoint -> Bool)
-> (TSPoint -> TSPoint -> Bool) -> Eq TSPoint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TSPoint -> TSPoint -> Bool
$c/= :: TSPoint -> TSPoint -> Bool
== :: TSPoint -> TSPoint -> Bool
$c== :: TSPoint -> TSPoint -> Bool
Eq, (forall x. TSPoint -> Rep TSPoint x)
-> (forall x. Rep TSPoint x -> TSPoint) -> Generic TSPoint
forall x. Rep TSPoint x -> TSPoint
forall x. TSPoint -> Rep TSPoint x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TSPoint x -> TSPoint
$cfrom :: forall x. TSPoint -> Rep TSPoint x
Generic)
data TSNode = TSNode !Word32 !TSPoint !Word32 !(Ptr ()) !(Ptr ())
deriving (Int -> TSNode -> ShowS
[TSNode] -> ShowS
TSNode -> String
(Int -> TSNode -> ShowS)
-> (TSNode -> String) -> ([TSNode] -> ShowS) -> Show TSNode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TSNode] -> ShowS
$cshowList :: [TSNode] -> ShowS
show :: TSNode -> String
$cshow :: TSNode -> String
showsPrec :: Int -> TSNode -> ShowS
$cshowsPrec :: Int -> TSNode -> ShowS
Show, TSNode -> TSNode -> Bool
(TSNode -> TSNode -> Bool)
-> (TSNode -> TSNode -> Bool) -> Eq TSNode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TSNode -> TSNode -> Bool
$c/= :: TSNode -> TSNode -> Bool
== :: TSNode -> TSNode -> Bool
$c== :: TSNode -> TSNode -> Bool
Eq, (forall x. TSNode -> Rep TSNode x)
-> (forall x. Rep TSNode x -> TSNode) -> Generic TSNode
forall x. Rep TSNode x -> TSNode
forall x. TSNode -> Rep TSNode x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TSNode x -> TSNode
$cfrom :: forall x. TSNode -> Rep TSNode x
Generic)
newtype FieldId = FieldId { FieldId -> TSSymbol
getFieldId :: Word16 }
deriving (FieldId -> FieldId -> Bool
(FieldId -> FieldId -> Bool)
-> (FieldId -> FieldId -> Bool) -> Eq FieldId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FieldId -> FieldId -> Bool
$c/= :: FieldId -> FieldId -> Bool
== :: FieldId -> FieldId -> Bool
$c== :: FieldId -> FieldId -> Bool
Eq, Eq FieldId
Eq FieldId
-> (FieldId -> FieldId -> Ordering)
-> (FieldId -> FieldId -> Bool)
-> (FieldId -> FieldId -> Bool)
-> (FieldId -> FieldId -> Bool)
-> (FieldId -> FieldId -> Bool)
-> (FieldId -> FieldId -> FieldId)
-> (FieldId -> FieldId -> FieldId)
-> Ord FieldId
FieldId -> FieldId -> Bool
FieldId -> FieldId -> Ordering
FieldId -> FieldId -> FieldId
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: FieldId -> FieldId -> FieldId
$cmin :: FieldId -> FieldId -> FieldId
max :: FieldId -> FieldId -> FieldId
$cmax :: FieldId -> FieldId -> FieldId
>= :: FieldId -> FieldId -> Bool
$c>= :: FieldId -> FieldId -> Bool
> :: FieldId -> FieldId -> Bool
$c> :: FieldId -> FieldId -> Bool
<= :: FieldId -> FieldId -> Bool
$c<= :: FieldId -> FieldId -> Bool
< :: FieldId -> FieldId -> Bool
$c< :: FieldId -> FieldId -> Bool
compare :: FieldId -> FieldId -> Ordering
$ccompare :: FieldId -> FieldId -> Ordering
$cp1Ord :: Eq FieldId
Ord, Int -> FieldId -> ShowS
[FieldId] -> ShowS
FieldId -> String
(Int -> FieldId -> ShowS)
-> (FieldId -> String) -> ([FieldId] -> ShowS) -> Show FieldId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FieldId] -> ShowS
$cshowList :: [FieldId] -> ShowS
show :: FieldId -> String
$cshow :: FieldId -> String
showsPrec :: Int -> FieldId -> ShowS
$cshowsPrec :: Int -> FieldId -> ShowS
Show, Ptr b -> Int -> IO FieldId
Ptr b -> Int -> FieldId -> IO ()
Ptr FieldId -> IO FieldId
Ptr FieldId -> Int -> IO FieldId
Ptr FieldId -> Int -> FieldId -> IO ()
Ptr FieldId -> FieldId -> IO ()
FieldId -> Int
(FieldId -> Int)
-> (FieldId -> Int)
-> (Ptr FieldId -> Int -> IO FieldId)
-> (Ptr FieldId -> Int -> FieldId -> IO ())
-> (forall b. Ptr b -> Int -> IO FieldId)
-> (forall b. Ptr b -> Int -> FieldId -> IO ())
-> (Ptr FieldId -> IO FieldId)
-> (Ptr FieldId -> FieldId -> IO ())
-> Storable FieldId
forall b. Ptr b -> Int -> IO FieldId
forall b. Ptr b -> Int -> FieldId -> IO ()
forall a.
(a -> Int)
-> (a -> Int)
-> (Ptr a -> Int -> IO a)
-> (Ptr a -> Int -> a -> IO ())
-> (forall b. Ptr b -> Int -> IO a)
-> (forall b. Ptr b -> Int -> a -> IO ())
-> (Ptr a -> IO a)
-> (Ptr a -> a -> IO ())
-> Storable a
poke :: Ptr FieldId -> FieldId -> IO ()
$cpoke :: Ptr FieldId -> FieldId -> IO ()
peek :: Ptr FieldId -> IO FieldId
$cpeek :: Ptr FieldId -> IO FieldId
pokeByteOff :: Ptr b -> Int -> FieldId -> IO ()
$cpokeByteOff :: forall b. Ptr b -> Int -> FieldId -> IO ()
peekByteOff :: Ptr b -> Int -> IO FieldId
$cpeekByteOff :: forall b. Ptr b -> Int -> IO FieldId
pokeElemOff :: Ptr FieldId -> Int -> FieldId -> IO ()
$cpokeElemOff :: Ptr FieldId -> Int -> FieldId -> IO ()
peekElemOff :: Ptr FieldId -> Int -> IO FieldId
$cpeekElemOff :: Ptr FieldId -> Int -> IO FieldId
alignment :: FieldId -> Int
$calignment :: FieldId -> Int
sizeOf :: FieldId -> Int
$csizeOf :: FieldId -> Int
Storable)
newtype Struct a = Struct { Struct a -> forall b. Ptr b -> IO (a, Ptr a)
runStruct :: forall b . Ptr b -> IO (a, Ptr a) }
evalStruct :: Struct a -> Ptr b -> IO a
evalStruct :: Struct a -> Ptr b -> IO a
evalStruct Struct a
s Ptr b
p = ((a, Ptr a) -> a) -> IO (a, Ptr a) -> IO a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a, Ptr a) -> a
forall a b. (a, b) -> a
fst (IO (a, Ptr a) -> IO a) -> IO (a, Ptr a) -> IO a
forall a b. (a -> b) -> a -> b
$! Struct a -> Ptr b -> IO (a, Ptr a)
forall a. Struct a -> forall b. Ptr b -> IO (a, Ptr a)
runStruct Struct a
s Ptr b
p
{-# INLINE evalStruct #-}
peekStruct :: forall a . Storable a => Struct a
peekStruct :: Struct a
peekStruct = (forall b. Ptr b -> IO (a, Ptr a)) -> Struct a
forall a. (forall b. Ptr b -> IO (a, Ptr a)) -> Struct a
Struct (\ Ptr b
p -> do
let aligned :: Ptr a
aligned = Ptr a -> Int -> Ptr a
forall a. Ptr a -> Int -> Ptr a
alignPtr (Ptr b -> Ptr a
forall a b. Ptr a -> Ptr b
castPtr Ptr b
p) (a -> Int
forall a. Storable a => a -> Int
alignment (a
forall a. HasCallStack => a
undefined :: a))
a
a <- Ptr a -> IO a
forall a. Storable a => Ptr a -> IO a
peek Ptr a
forall a. Ptr a
aligned
(a, Ptr a) -> IO (a, Ptr a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a
a, Ptr Any
forall a. Ptr a
aligned Ptr Any -> Int -> Ptr a
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` a -> Int
forall a. Storable a => a -> Int
sizeOf a
a))
{-# INLINE peekStruct #-}
pokeStruct :: Storable a => a -> Struct ()
pokeStruct :: a -> Struct ()
pokeStruct a
a = (forall b. Ptr b -> IO ((), Ptr ())) -> Struct ()
forall a. (forall b. Ptr b -> IO (a, Ptr a)) -> Struct a
Struct (\ Ptr b
p -> do
let aligned :: Ptr a
aligned = Ptr a -> Int -> Ptr a
forall a. Ptr a -> Int -> Ptr a
alignPtr (Ptr b -> Ptr a
forall a b. Ptr a -> Ptr b
castPtr Ptr b
p) (a -> Int
forall a. Storable a => a -> Int
alignment a
a)
Ptr a -> a -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr a
forall a. Ptr a
aligned a
a
((), Ptr ()) -> IO ((), Ptr ())
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((), Ptr Any -> Ptr Any
forall a b. Ptr a -> Ptr b
castPtr Ptr Any
forall a. Ptr a
aligned Ptr Any -> Int -> Ptr ()
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` a -> Int
forall a. Storable a => a -> Int
sizeOf a
a))
{-# INLINE pokeStruct #-}
instance Storable Node where
alignment :: Node -> Int
alignment Node
_ = TSNode -> Int
forall a. Storable a => a -> Int
alignment (TSNode
forall a. HasCallStack => a
undefined :: TSNode)
{-# INLINE alignment #-}
sizeOf :: Node -> Int
sizeOf Node
_ = Int
80
{-# INLINE sizeOf #-}
peek :: Ptr Node -> IO Node
peek = Struct Node -> Ptr Node -> IO Node
forall a b. Struct a -> Ptr b -> IO a
evalStruct (Struct Node -> Ptr Node -> IO Node)
-> Struct Node -> Ptr Node -> IO Node
forall a b. (a -> b) -> a -> b
$ TSNode
-> CString
-> TSSymbol
-> TSPoint
-> Word32
-> Word32
-> CString
-> CBool
-> CBool
-> Node
Node (TSNode
-> CString
-> TSSymbol
-> TSPoint
-> Word32
-> Word32
-> CString
-> CBool
-> CBool
-> Node)
-> Struct TSNode
-> Struct
(CString
-> TSSymbol
-> TSPoint
-> Word32
-> Word32
-> CString
-> CBool
-> CBool
-> Node)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Struct TSNode
forall a. Storable a => Struct a
peekStruct
Struct
(CString
-> TSSymbol
-> TSPoint
-> Word32
-> Word32
-> CString
-> CBool
-> CBool
-> Node)
-> Struct CString
-> Struct
(TSSymbol
-> TSPoint
-> Word32
-> Word32
-> CString
-> CBool
-> CBool
-> Node)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Struct CString
forall a. Storable a => Struct a
peekStruct
Struct
(TSSymbol
-> TSPoint
-> Word32
-> Word32
-> CString
-> CBool
-> CBool
-> Node)
-> Struct TSSymbol
-> Struct
(TSPoint -> Word32 -> Word32 -> CString -> CBool -> CBool -> Node)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Struct TSSymbol
forall a. Storable a => Struct a
peekStruct
Struct
(TSPoint -> Word32 -> Word32 -> CString -> CBool -> CBool -> Node)
-> Struct TSPoint
-> Struct (Word32 -> Word32 -> CString -> CBool -> CBool -> Node)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Struct TSPoint
forall a. Storable a => Struct a
peekStruct
Struct (Word32 -> Word32 -> CString -> CBool -> CBool -> Node)
-> Struct Word32
-> Struct (Word32 -> CString -> CBool -> CBool -> Node)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Struct Word32
forall a. Storable a => Struct a
peekStruct
Struct (Word32 -> CString -> CBool -> CBool -> Node)
-> Struct Word32 -> Struct (CString -> CBool -> CBool -> Node)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Struct Word32
forall a. Storable a => Struct a
peekStruct
Struct (CString -> CBool -> CBool -> Node)
-> Struct CString -> Struct (CBool -> CBool -> Node)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Struct CString
forall a. Storable a => Struct a
peekStruct
Struct (CBool -> CBool -> Node)
-> Struct CBool -> Struct (CBool -> Node)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Struct CBool
forall a. Storable a => Struct a
peekStruct
Struct (CBool -> Node) -> Struct CBool -> Struct Node
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Struct CBool
forall a. Storable a => Struct a
peekStruct
{-# INLINE peek #-}
poke :: Ptr Node -> Node -> IO ()
poke Ptr Node
ptr (Node TSNode
n CString
t TSSymbol
s TSPoint
ep Word32
eb Word32
c CString
fn CBool
nn CBool
ne) = (Struct () -> Ptr Node -> IO ()) -> Ptr Node -> Struct () -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Struct () -> Ptr Node -> IO ()
forall a b. Struct a -> Ptr b -> IO a
evalStruct Ptr Node
ptr (Struct () -> IO ()) -> Struct () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
TSNode -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct TSNode
n
CString -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct CString
t
TSSymbol -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct TSSymbol
s
TSPoint -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct TSPoint
ep
Word32 -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct Word32
eb
Word32 -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct Word32
c
CString -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct CString
fn
CBool -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct CBool
nn
CBool -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct CBool
ne
{-# INLINE poke #-}
instance Storable TSPoint where
alignment :: TSPoint -> Int
alignment TSPoint
_ = Int32 -> Int
forall a. Storable a => a -> Int
alignment (Int32
0 :: Int32)
{-# INLINE alignment #-}
sizeOf :: TSPoint -> Int
sizeOf TSPoint
_ = Int
8
{-# INLINE sizeOf #-}
peek :: Ptr TSPoint -> IO TSPoint
peek = Struct TSPoint -> Ptr TSPoint -> IO TSPoint
forall a b. Struct a -> Ptr b -> IO a
evalStruct (Struct TSPoint -> Ptr TSPoint -> IO TSPoint)
-> Struct TSPoint -> Ptr TSPoint -> IO TSPoint
forall a b. (a -> b) -> a -> b
$ Word32 -> Word32 -> TSPoint
TSPoint (Word32 -> Word32 -> TSPoint)
-> Struct Word32 -> Struct (Word32 -> TSPoint)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Struct Word32
forall a. Storable a => Struct a
peekStruct
Struct (Word32 -> TSPoint) -> Struct Word32 -> Struct TSPoint
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Struct Word32
forall a. Storable a => Struct a
peekStruct
{-# INLINE peek #-}
poke :: Ptr TSPoint -> TSPoint -> IO ()
poke Ptr TSPoint
ptr (TSPoint Word32
r Word32
c) = (Struct () -> Ptr TSPoint -> IO ())
-> Ptr TSPoint -> Struct () -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Struct () -> Ptr TSPoint -> IO ()
forall a b. Struct a -> Ptr b -> IO a
evalStruct Ptr TSPoint
ptr (Struct () -> IO ()) -> Struct () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
Word32 -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct Word32
r
Word32 -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct Word32
c
{-# INLINE poke #-}
instance Storable TSNode where
alignment :: TSNode -> Int
alignment TSNode
_ = Ptr () -> Int
forall a. Storable a => a -> Int
alignment (Ptr ()
forall a. Ptr a
nullPtr :: Ptr ())
{-# INLINE alignment #-}
sizeOf :: TSNode -> Int
sizeOf TSNode
_ = Int
32
{-# INLINE sizeOf #-}
peek :: Ptr TSNode -> IO TSNode
peek = Struct TSNode -> Ptr TSNode -> IO TSNode
forall a b. Struct a -> Ptr b -> IO a
evalStruct (Struct TSNode -> Ptr TSNode -> IO TSNode)
-> Struct TSNode -> Ptr TSNode -> IO TSNode
forall a b. (a -> b) -> a -> b
$ Word32 -> TSPoint -> Word32 -> Ptr () -> Ptr () -> TSNode
TSNode (Word32 -> TSPoint -> Word32 -> Ptr () -> Ptr () -> TSNode)
-> Struct Word32
-> Struct (TSPoint -> Word32 -> Ptr () -> Ptr () -> TSNode)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Struct Word32
forall a. Storable a => Struct a
peekStruct
Struct (TSPoint -> Word32 -> Ptr () -> Ptr () -> TSNode)
-> Struct TSPoint -> Struct (Word32 -> Ptr () -> Ptr () -> TSNode)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Struct TSPoint
forall a. Storable a => Struct a
peekStruct
Struct (Word32 -> Ptr () -> Ptr () -> TSNode)
-> Struct Word32 -> Struct (Ptr () -> Ptr () -> TSNode)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Struct Word32
forall a. Storable a => Struct a
peekStruct
Struct (Ptr () -> Ptr () -> TSNode)
-> Struct (Ptr ()) -> Struct (Ptr () -> TSNode)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Struct (Ptr ())
forall a. Storable a => Struct a
peekStruct
Struct (Ptr () -> TSNode) -> Struct (Ptr ()) -> Struct TSNode
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Struct (Ptr ())
forall a. Storable a => Struct a
peekStruct
{-# INLINE peek #-}
poke :: Ptr TSNode -> TSNode -> IO ()
poke Ptr TSNode
ptr (TSNode Word32
sb TSPoint
sp Word32
o4 Ptr ()
p1 Ptr ()
p2) = (Struct () -> Ptr TSNode -> IO ())
-> Ptr TSNode -> Struct () -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Struct () -> Ptr TSNode -> IO ()
forall a b. Struct a -> Ptr b -> IO a
evalStruct Ptr TSNode
ptr (Struct () -> IO ()) -> Struct () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
Word32 -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct Word32
sb
TSPoint -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct TSPoint
sp
Word32 -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct Word32
o4
Ptr () -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct Ptr ()
p1
Ptr () -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct Ptr ()
p2
{-# INLINE poke #-}
instance Functor Struct where
fmap :: (a -> b) -> Struct a -> Struct b
fmap a -> b
f Struct a
a = (forall b. Ptr b -> IO (b, Ptr b)) -> Struct b
forall a. (forall b. Ptr b -> IO (a, Ptr a)) -> Struct a
Struct forall b. Ptr b -> IO (b, Ptr b)
forall b b. Ptr b -> IO (b, Ptr b)
go where
go :: Ptr b -> IO (b, Ptr b)
go Ptr b
p = do
(a
a', Ptr a
p') <- Struct a -> Ptr b -> IO (a, Ptr a)
forall a. Struct a -> forall b. Ptr b -> IO (a, Ptr a)
runStruct Struct a
a Ptr b
p
let fa :: b
fa = a -> b
f a
a'
b
fa b -> IO (b, Ptr b) -> IO (b, Ptr b)
`seq` Ptr a
p' Ptr a -> IO (b, Ptr b) -> IO (b, Ptr b)
`seq` (b, Ptr b) -> IO (b, Ptr b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (b
fa, Ptr a -> Ptr b
forall a b. Ptr a -> Ptr b
castPtr Ptr a
p')
{-# INLINE go #-}
{-# INLINE fmap #-}
instance Applicative Struct where
pure :: a -> Struct a
pure a
a = (forall b. Ptr b -> IO (a, Ptr a)) -> Struct a
forall a. (forall b. Ptr b -> IO (a, Ptr a)) -> Struct a
Struct (\ Ptr b
p -> (a, Ptr a) -> IO (a, Ptr a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a
a, Ptr b -> Ptr a
forall a b. Ptr a -> Ptr b
castPtr Ptr b
p))
{-# INLINE pure #-}
Struct (a -> b)
f <*> :: Struct (a -> b) -> Struct a -> Struct b
<*> Struct a
a = (forall b. Ptr b -> IO (b, Ptr b)) -> Struct b
forall a. (forall b. Ptr b -> IO (a, Ptr a)) -> Struct a
Struct forall b. Ptr b -> IO (b, Ptr b)
forall b b. Ptr b -> IO (b, Ptr b)
go where
go :: Ptr b -> IO (b, Ptr b)
go Ptr b
p = do
(a -> b
f', Ptr (a -> b)
p') <- Struct (a -> b) -> Ptr b -> IO (a -> b, Ptr (a -> b))
forall a. Struct a -> forall b. Ptr b -> IO (a, Ptr a)
runStruct Struct (a -> b)
f Ptr b
p
(a
a', Ptr a
p'') <- Ptr (a -> b)
p' Ptr (a -> b) -> IO (a, Ptr a) -> IO (a, Ptr a)
`seq` Struct a -> Ptr Any -> IO (a, Ptr a)
forall a. Struct a -> forall b. Ptr b -> IO (a, Ptr a)
runStruct Struct a
a (Ptr (a -> b) -> Ptr Any
forall a b. Ptr a -> Ptr b
castPtr Ptr (a -> b)
p')
let fa :: b
fa = a -> b
f' a
a'
b
fa b -> IO (b, Ptr b) -> IO (b, Ptr b)
`seq` Ptr a
p'' Ptr a -> IO (b, Ptr b) -> IO (b, Ptr b)
`seq` (b, Ptr b) -> IO (b, Ptr b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (b
fa, Ptr a -> Ptr b
forall a b. Ptr a -> Ptr b
castPtr Ptr a
p'')
{-# INLINE go #-}
{-# INLINE (<*>) #-}
instance Monad Struct where
return :: a -> Struct a
return = a -> Struct a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
{-# INLINE return #-}
Struct a
a >>= :: Struct a -> (a -> Struct b) -> Struct b
>>= a -> Struct b
f = (forall b. Ptr b -> IO (b, Ptr b)) -> Struct b
forall a. (forall b. Ptr b -> IO (a, Ptr a)) -> Struct a
Struct forall b. Ptr b -> IO (b, Ptr b)
go where
go :: Ptr b -> IO (b, Ptr b)
go Ptr b
p = do
(a
a', Ptr a
p') <- Struct a -> Ptr b -> IO (a, Ptr a)
forall a. Struct a -> forall b. Ptr b -> IO (a, Ptr a)
runStruct Struct a
a Ptr b
p
(b
fa', Ptr b
p'') <- Ptr a
p' Ptr a -> IO (b, Ptr b) -> IO (b, Ptr b)
`seq` Struct b -> Ptr Any -> IO (b, Ptr b)
forall a. Struct a -> forall b. Ptr b -> IO (a, Ptr a)
runStruct (a -> Struct b
f a
a') (Ptr a -> Ptr Any
forall a b. Ptr a -> Ptr b
castPtr Ptr a
p')
b
fa' b -> IO (b, Ptr b) -> IO (b, Ptr b)
`seq` Ptr b
p'' Ptr b -> IO (b, Ptr b) -> IO (b, Ptr b)
`seq` (b, Ptr b) -> IO (b, Ptr b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (b
fa', Ptr b
p'')
{-# INLINE go #-}
{-# INLINE (>>=) #-}
foreign import ccall unsafe "src/bridge.c ts_node_copy_child_nodes" ts_node_copy_child_nodes :: Ptr TSNode -> Ptr Node -> IO ()
foreign import ccall unsafe "src/bridge.c ts_node_poke_p" ts_node_poke_p :: Ptr TSNode -> Ptr Node -> IO ()