{-# LANGUAGE DeriveGeneric, GeneralizedNewtypeDeriving, InterruptibleFFI, RankNTypes, ScopedTypeVariables #-}
{-# OPTIONS_GHC -funbox-strict-fields #-}
module TreeSitter.Node
( Node(..)
, 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
nodeStartPoint :: !TSPoint
  , Node -> TSPoint
nodeEndPoint   :: !TSPoint
  , Node -> Word32
nodeStartByte  :: !Word32
  , Node -> Word32
nodeEndByte    :: !Word32
  , Node -> Word32
nodeChildCount :: !Word32
  , Node -> CBool
nodeIsNamed    :: !CBool
  , Node -> CBool
nodeIsExtra    :: !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)

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 !Word32 !Word32 !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)


-- | 'Struct' is a strict 'Monad' with automatic alignment & advancing, & inferred type.
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 s :: Struct a
s p :: 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 (\ p :: 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
a = (forall b. Ptr b -> IO ((), Ptr ())) -> Struct ()
forall a. (forall b. Ptr b -> IO (a, Ptr a)) -> Struct a
Struct (\ p :: 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 _ = TSNode -> Int
forall a. Storable a => a -> Int
alignment (Word32 -> Word32 -> Word32 -> Word32 -> Ptr () -> Ptr () -> TSNode
TSNode 0 0 0 0 Ptr ()
forall a. Ptr a
nullPtr Ptr ()
forall a. Ptr a
nullPtr :: TSNode)
  sizeOf :: Node -> Int
sizeOf _ = 80
  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
-> TSPoint
-> Word32
-> Word32
-> Word32
-> CBool
-> CBool
-> Node
Node (TSNode
 -> CString
 -> TSSymbol
 -> TSPoint
 -> TSPoint
 -> Word32
 -> Word32
 -> Word32
 -> CBool
 -> CBool
 -> Node)
-> Struct TSNode
-> Struct
     (CString
      -> TSSymbol
      -> TSPoint
      -> TSPoint
      -> Word32
      -> Word32
      -> Word32
      -> 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
   -> TSPoint
   -> Word32
   -> Word32
   -> Word32
   -> CBool
   -> CBool
   -> Node)
-> Struct CString
-> Struct
     (TSSymbol
      -> TSPoint
      -> TSPoint
      -> Word32
      -> Word32
      -> Word32
      -> 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
   -> TSPoint
   -> Word32
   -> Word32
   -> Word32
   -> CBool
   -> CBool
   -> Node)
-> Struct TSSymbol
-> Struct
     (TSPoint
      -> TSPoint -> Word32 -> Word32 -> Word32 -> 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
   -> TSPoint -> Word32 -> Word32 -> Word32 -> CBool -> CBool -> Node)
-> Struct TSPoint
-> Struct
     (TSPoint -> Word32 -> Word32 -> Word32 -> 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
  (TSPoint -> Word32 -> Word32 -> Word32 -> CBool -> CBool -> Node)
-> Struct TSPoint
-> Struct (Word32 -> Word32 -> Word32 -> 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 -> Word32 -> CBool -> CBool -> Node)
-> Struct Word32
-> Struct (Word32 -> Word32 -> 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 -> Word32 -> CBool -> CBool -> Node)
-> Struct Word32 -> Struct (Word32 -> 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 -> CBool -> CBool -> Node)
-> Struct Word32 -> Struct (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 (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
  poke :: Ptr Node -> Node -> IO ()
poke ptr :: Ptr Node
ptr (Node n :: TSNode
n t :: CString
t s :: TSSymbol
s sp :: TSPoint
sp ep :: TSPoint
ep sb :: Word32
sb eb :: Word32
eb c :: Word32
c nn :: CBool
nn ne :: 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
sp
    TSPoint -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct TSPoint
ep
    Word32 -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct Word32
sb
    Word32 -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct Word32
eb
    Word32 -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct Word32
c
    CBool -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct CBool
nn
    CBool -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct CBool
ne

instance Storable TSPoint where
  alignment :: TSPoint -> Int
alignment _ = Int32 -> Int
forall a. Storable a => a -> Int
alignment (0 :: Int32)
  sizeOf :: TSPoint -> Int
sizeOf _ = 8
  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
  poke :: Ptr TSPoint -> TSPoint -> IO ()
poke ptr :: Ptr TSPoint
ptr (TSPoint r :: Word32
r c :: 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

instance Storable TSNode where
  alignment :: TSNode -> Int
alignment _ = Ptr () -> Int
forall a. Storable a => a -> Int
alignment (Ptr ()
forall a. Ptr a
nullPtr :: Ptr ())
  sizeOf :: TSNode -> Int
sizeOf _ = 32
  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 -> Word32 -> Word32 -> Word32 -> Ptr () -> Ptr () -> TSNode
TSNode (Word32
 -> Word32 -> Word32 -> Word32 -> Ptr () -> Ptr () -> TSNode)
-> Struct Word32
-> Struct
     (Word32 -> Word32 -> 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 (Word32 -> Word32 -> Word32 -> Ptr () -> Ptr () -> TSNode)
-> Struct Word32
-> Struct (Word32 -> Word32 -> 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 (Word32 -> Word32 -> Ptr () -> Ptr () -> TSNode)
-> Struct Word32 -> Struct (Word32 -> 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 (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
  poke :: Ptr TSNode -> TSNode -> IO ()
poke ptr :: Ptr TSNode
ptr (TSNode o1 :: Word32
o1 o2 :: Word32
o2 o3 :: Word32
o3 o4 :: Word32
o4 p1 :: Ptr ()
p1 p2 :: 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
o1
    Word32 -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct Word32
o2
    Word32 -> Struct ()
forall a. Storable a => a -> Struct ()
pokeStruct Word32
o3
    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

instance Functor Struct where
  fmap :: (a -> b) -> Struct a -> Struct b
fmap f :: a -> b
f a :: 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 (\ p :: Ptr b
p -> do
    (a' :: a
a', p' :: 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)
forall a b. a -> b -> b
`seq` Ptr a
p' Ptr a -> IO (b, Ptr b) -> IO (b, Ptr b)
forall a b. a -> b -> 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 fmap #-}

instance Applicative Struct where
  pure :: a -> Struct a
pure a :: 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 (\ p :: 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 #-}

  f :: Struct (a -> b)
f <*> :: Struct (a -> b) -> Struct a -> Struct b
<*> a :: 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 (\ p :: Ptr b
p -> do
    (f' :: a -> b
f', p' :: 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
a', p'' :: Ptr a
p'') <- Ptr (a -> b)
p' Ptr (a -> b) -> IO (a, Ptr a) -> IO (a, Ptr a)
forall a b. a -> b -> b
`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)
forall a b. a -> b -> b
`seq` Ptr a
p'' Ptr a -> IO (b, Ptr b) -> IO (b, Ptr b)
forall a b. a -> b -> 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 (<*>) #-}

instance Monad Struct where
  return :: a -> Struct a
return = a -> Struct a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
  {-# INLINE return #-}

  a :: Struct a
a >>= :: Struct a -> (a -> Struct b) -> Struct b
>>= f :: 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 (\ p :: Ptr b
p -> do
    (a' :: a
a', p' :: 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
    (fa' :: b
fa', p'' :: Ptr b
p'') <- Ptr a
p' Ptr a -> IO (b, Ptr b) -> IO (b, Ptr b)
forall a b. a -> b -> 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)
forall a b. a -> b -> b
`seq` Ptr b
p'' Ptr b -> IO (b, Ptr b) -> IO (b, Ptr b)
forall a b. a -> b -> b
`seq` (b, Ptr b) -> IO (b, Ptr b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (b
fa', Ptr b
p''))
  {-# INLINE (>>=) #-}


foreign import ccall interruptible "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 ()