-- | Parsing of objects.
module Data.GI.GIR.Object
    ( Object(..)
    , parseObject
    ) where

import Data.Text (Text)

import Data.GI.GIR.Method (Method, parseMethod, MethodType(..))
import Data.GI.GIR.Property (Property, parseProperty)
import Data.GI.GIR.Signal (Signal, parseSignal)
import Data.GI.GIR.Parser
import Data.GI.GIR.Type (queryCType)

data Object = Object {
    Object -> Maybe Name
objParent :: Maybe Name,
    Object -> Text
objTypeInit :: Text,
    Object -> Text
objTypeName :: Text,
    Object -> Maybe Text
objCType :: Maybe Text,
    Object -> [Name]
objInterfaces :: [Name],
    Object -> Maybe DeprecationInfo
objDeprecated :: Maybe DeprecationInfo,
    Object -> Documentation
objDocumentation :: Documentation,
    Object -> [Method]
objMethods :: [Method],
    Object -> [Property]
objProperties :: [Property],
    Object -> [Signal]
objSignals :: [Signal]
    } deriving Int -> Object -> ShowS
[Object] -> ShowS
Object -> String
(Int -> Object -> ShowS)
-> (Object -> String) -> ([Object] -> ShowS) -> Show Object
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Object] -> ShowS
$cshowList :: [Object] -> ShowS
show :: Object -> String
$cshow :: Object -> String
showsPrec :: Int -> Object -> ShowS
$cshowsPrec :: Int -> Object -> ShowS
Show

parseObject :: Parser (Name, Object)
parseObject :: Parser (Name, Object)
parseObject = do
  Name
name <- Parser Name
parseName
  Maybe DeprecationInfo
deprecated <- Parser (Maybe DeprecationInfo)
parseDeprecation
  Documentation
doc <- Parser Documentation
parseDocumentation
  [Method]
methods <- Text -> Parser Method -> Parser [Method]
forall a. Text -> Parser a -> Parser [a]
parseChildrenWithLocalName "method" (MethodType -> Parser Method
parseMethod MethodType
OrdinaryMethod)
  [Method]
constructors <- Text -> Parser Method -> Parser [Method]
forall a. Text -> Parser a -> Parser [a]
parseChildrenWithLocalName "constructor" (MethodType -> Parser Method
parseMethod MethodType
Constructor)
  [Method]
functions <- Text -> Parser Method -> Parser [Method]
forall a. Text -> Parser a -> Parser [a]
parseChildrenWithLocalName "function" (MethodType -> Parser Method
parseMethod MethodType
MemberFunction)
  Maybe Name
parent <- Name
-> Maybe Name
-> (Text -> Parser (Maybe Name))
-> Parser (Maybe Name)
forall a. Name -> a -> (Text -> Parser a) -> Parser a
optionalAttr "parent" Maybe Name
forall a. Maybe a
Nothing ((Name -> Maybe Name) -> Parser Name -> Parser (Maybe Name)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Name -> Maybe Name
forall a. a -> Maybe a
Just (Parser Name -> Parser (Maybe Name))
-> (Text -> Parser Name) -> Text -> Parser (Maybe Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Parser Name
qualifyName)
  [Name]
interfaces <- Text -> Parser Name -> Parser [Name]
forall a. Text -> Parser a -> Parser [a]
parseChildrenWithLocalName "implements" Parser Name
parseName
  [Property]
props <- Text -> Parser Property -> Parser [Property]
forall a. Text -> Parser a -> Parser [a]
parseChildrenWithLocalName "property" Parser Property
parseProperty
  Text
typeInit <- GIRXMLNamespace -> Name -> Parser Text
getAttrWithNamespace GIRXMLNamespace
GLibGIRNS "get-type"
  Text
typeName <- GIRXMLNamespace -> Name -> Parser Text
getAttrWithNamespace GIRXMLNamespace
GLibGIRNS "type-name"
  [Signal]
signals <- GIRXMLNamespace -> Text -> Parser Signal -> Parser [Signal]
forall a. GIRXMLNamespace -> Text -> Parser a -> Parser [a]
parseChildrenWithNSName GIRXMLNamespace
GLibGIRNS "signal" Parser Signal
parseSignal
  Maybe Text
ctype <- Parser (Maybe Text)
queryCType
  (Name, Object) -> Parser (Name, Object)
forall (m :: * -> *) a. Monad m => a -> m a
return (Name
name,
         Object :: Maybe Name
-> Text
-> Text
-> Maybe Text
-> [Name]
-> Maybe DeprecationInfo
-> Documentation
-> [Method]
-> [Property]
-> [Signal]
-> Object
Object {
            objParent :: Maybe Name
objParent = Maybe Name
parent
          , objTypeInit :: Text
objTypeInit = Text
typeInit
          , objCType :: Maybe Text
objCType = Maybe Text
ctype
          , objTypeName :: Text
objTypeName = Text
typeName
          , objInterfaces :: [Name]
objInterfaces = [Name]
interfaces
          , objDeprecated :: Maybe DeprecationInfo
objDeprecated = Maybe DeprecationInfo
deprecated
          , objDocumentation :: Documentation
objDocumentation = Documentation
doc
          , objMethods :: [Method]
objMethods = [Method]
constructors [Method] -> [Method] -> [Method]
forall a. [a] -> [a] -> [a]
++ [Method]
methods [Method] -> [Method] -> [Method]
forall a. [a] -> [a] -> [a]
++ [Method]
functions
          , objProperties :: [Property]
objProperties = [Property]
props
          , objSignals :: [Signal]
objSignals = [Signal]
signals
          })