module Data.GI.GIR.Callable ( Callable(..) , parseCallable ) where import Data.GI.GIR.Arg (Arg(..), parseArg, parseTransfer) import Data.GI.GIR.BasicTypes (Transfer(..), Type) import Data.GI.GIR.Parser import Data.GI.GIR.Type (parseOptionalType) data Callable = Callable { Callable -> Maybe Type returnType :: Maybe Type, Callable -> Bool returnMayBeNull :: Bool, Callable -> Transfer returnTransfer :: Transfer, Callable -> Documentation returnDocumentation :: Documentation, Callable -> [Arg] args :: [Arg], Callable -> Bool skipReturn :: Bool, Callable -> Bool callableThrows :: Bool, Callable -> Maybe DeprecationInfo callableDeprecated :: Maybe DeprecationInfo, Callable -> Documentation callableDocumentation :: Documentation } deriving (Int -> Callable -> ShowS [Callable] -> ShowS Callable -> String (Int -> Callable -> ShowS) -> (Callable -> String) -> ([Callable] -> ShowS) -> Show Callable forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [Callable] -> ShowS $cshowList :: [Callable] -> ShowS show :: Callable -> String $cshow :: Callable -> String showsPrec :: Int -> Callable -> ShowS $cshowsPrec :: Int -> Callable -> ShowS Show, Callable -> Callable -> Bool (Callable -> Callable -> Bool) -> (Callable -> Callable -> Bool) -> Eq Callable forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: Callable -> Callable -> Bool $c/= :: Callable -> Callable -> Bool == :: Callable -> Callable -> Bool $c== :: Callable -> Callable -> Bool Eq) parseArgs :: Parser [Arg] parseArgs :: Parser [Arg] parseArgs = do [[Arg]] paramSets <- Text -> Parser [Arg] -> Parser [[Arg]] forall a. Text -> Parser a -> Parser [a] parseChildrenWithLocalName "parameters" Parser [Arg] parseArgSet case [[Arg]] paramSets of [] -> [Arg] -> Parser [Arg] forall (m :: * -> *) a. Monad m => a -> m a return [] (ps :: [Arg] ps:[]) -> [Arg] -> Parser [Arg] forall (m :: * -> *) a. Monad m => a -> m a return [Arg] ps _ -> Text -> Parser [Arg] forall a. Text -> Parser a parseError (Text -> Parser [Arg]) -> Text -> Parser [Arg] forall a b. (a -> b) -> a -> b $ "Unexpected multiple \"parameters\" tag" where parseArgSet :: Parser [Arg] parseArgSet = Text -> Parser Arg -> Parser [Arg] forall a. Text -> Parser a -> Parser [a] parseChildrenWithLocalName "parameter" Parser Arg parseArg parseOneReturn :: Parser (Maybe Type, Bool, Transfer, Bool, Documentation) parseOneReturn :: Parser (Maybe Type, Bool, Transfer, Bool, Documentation) parseOneReturn = do Maybe Type returnType <- Parser (Maybe Type) parseOptionalType Bool allowNone <- Name -> Bool -> (Text -> Parser Bool) -> Parser Bool forall a. Name -> a -> (Text -> Parser a) -> Parser a optionalAttr "allow-none" Bool False Text -> Parser Bool parseBool Bool nullable <- Name -> Bool -> (Text -> Parser Bool) -> Parser Bool forall a. Name -> a -> (Text -> Parser a) -> Parser a optionalAttr "nullable" Bool False Text -> Parser Bool parseBool Transfer transfer <- Parser Transfer parseTransfer Documentation doc <- Parser Documentation parseDocumentation Bool skip <- Name -> Bool -> (Text -> Parser Bool) -> Parser Bool forall a. Name -> a -> (Text -> Parser a) -> Parser a optionalAttr "skip" Bool False Text -> Parser Bool parseBool (Maybe Type, Bool, Transfer, Bool, Documentation) -> Parser (Maybe Type, Bool, Transfer, Bool, Documentation) forall (m :: * -> *) a. Monad m => a -> m a return (Maybe Type returnType, Bool allowNone Bool -> Bool -> Bool || Bool nullable, Transfer transfer, Bool skip, Documentation doc) parseReturn :: Parser (Maybe Type, Bool, Transfer, Bool, Documentation) parseReturn :: Parser (Maybe Type, Bool, Transfer, Bool, Documentation) parseReturn = do [(Maybe Type, Bool, Transfer, Bool, Documentation)] returnSets <- Text -> Parser (Maybe Type, Bool, Transfer, Bool, Documentation) -> Parser [(Maybe Type, Bool, Transfer, Bool, Documentation)] forall a. Text -> Parser a -> Parser [a] parseChildrenWithLocalName "return-value" Parser (Maybe Type, Bool, Transfer, Bool, Documentation) parseOneReturn case [(Maybe Type, Bool, Transfer, Bool, Documentation)] returnSets of (r :: (Maybe Type, Bool, Transfer, Bool, Documentation) r:[]) -> (Maybe Type, Bool, Transfer, Bool, Documentation) -> Parser (Maybe Type, Bool, Transfer, Bool, Documentation) forall (m :: * -> *) a. Monad m => a -> m a return (Maybe Type, Bool, Transfer, Bool, Documentation) r [] -> Text -> Parser (Maybe Type, Bool, Transfer, Bool, Documentation) forall a. Text -> Parser a parseError (Text -> Parser (Maybe Type, Bool, Transfer, Bool, Documentation)) -> Text -> Parser (Maybe Type, Bool, Transfer, Bool, Documentation) forall a b. (a -> b) -> a -> b $ "No return information found" _ -> Text -> Parser (Maybe Type, Bool, Transfer, Bool, Documentation) forall a. Text -> Parser a parseError (Text -> Parser (Maybe Type, Bool, Transfer, Bool, Documentation)) -> Text -> Parser (Maybe Type, Bool, Transfer, Bool, Documentation) forall a b. (a -> b) -> a -> b $ "Multiple return values found" parseCallable :: Parser Callable parseCallable :: Parser Callable parseCallable = do [Arg] args <- Parser [Arg] parseArgs (returnType :: Maybe Type returnType, mayBeNull :: Bool mayBeNull, transfer :: Transfer transfer, skip :: Bool skip, returnDoc :: Documentation returnDoc) <- Parser (Maybe Type, Bool, Transfer, Bool, Documentation) parseReturn Maybe DeprecationInfo deprecated <- Parser (Maybe DeprecationInfo) parseDeprecation Documentation docs <- Parser Documentation parseDocumentation Bool throws <- Name -> Bool -> (Text -> Parser Bool) -> Parser Bool forall a. Name -> a -> (Text -> Parser a) -> Parser a optionalAttr "throws" Bool False Text -> Parser Bool parseBool Callable -> Parser Callable forall (m :: * -> *) a. Monad m => a -> m a return (Callable -> Parser Callable) -> Callable -> Parser Callable forall a b. (a -> b) -> a -> b $ Callable :: Maybe Type -> Bool -> Transfer -> Documentation -> [Arg] -> Bool -> Bool -> Maybe DeprecationInfo -> Documentation -> Callable Callable { returnType :: Maybe Type returnType = Maybe Type returnType , returnMayBeNull :: Bool returnMayBeNull = Bool mayBeNull , returnTransfer :: Transfer returnTransfer = Transfer transfer , returnDocumentation :: Documentation returnDocumentation = Documentation returnDoc , args :: [Arg] args = [Arg] args , skipReturn :: Bool skipReturn = Bool skip , callableThrows :: Bool callableThrows = Bool throws , callableDeprecated :: Maybe DeprecationInfo callableDeprecated = Maybe DeprecationInfo deprecated , callableDocumentation :: Documentation callableDocumentation = Documentation docs }