-- | Parsing of callbacks.
module Data.GI.GIR.Callback
    ( Callback(..)
    , parseCallback
    ) where

import Data.Text (Text)

import Data.GI.GIR.Callable (Callable, parseCallable)
import Data.GI.GIR.Parser
import Data.GI.GIR.Type (queryCType)

data Callback = Callback { Callback -> Callable
cbCallable :: Callable
                         , Callback -> Maybe ParseError
cbCType    :: Maybe Text
                         , Callback -> Documentation
cbDocumentation :: Documentation
                         }
    deriving Int -> Callback -> ShowS
[Callback] -> ShowS
Callback -> String
(Int -> Callback -> ShowS)
-> (Callback -> String) -> ([Callback] -> ShowS) -> Show Callback
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Callback -> ShowS
showsPrec :: Int -> Callback -> ShowS
$cshow :: Callback -> String
show :: Callback -> String
$cshowList :: [Callback] -> ShowS
showList :: [Callback] -> ShowS
Show

parseCallback :: Parser (Name, Callback)
parseCallback :: Parser (Name, Callback)
parseCallback = do
  Name
name <- Parser Name
parseName
  Callable
callable <- Parser Callable
parseCallable
  Maybe ParseError
ctype <- Parser (Maybe ParseError)
queryCType
  Documentation
doc <- Parser Documentation
parseDocumentation
  (Name, Callback) -> Parser (Name, Callback)
forall a. a -> ReaderT ParseContext (Except ParseError) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Name
name, Callback { cbCallable :: Callable
cbCallable = Callable
callable
                         , cbCType :: Maybe ParseError
cbCType = Maybe ParseError
ctype
                         , cbDocumentation :: Documentation
cbDocumentation = Documentation
doc })