module Data.GI.GIR.Constant
( Constant(..)
, parseConstant
) where
import Data.Text (Text)
import Data.GI.GIR.BasicTypes (Type)
import Data.GI.GIR.Type (parseType)
import Data.GI.GIR.Parser
data Constant = Constant {
Constant -> Type
constantType :: Type,
Constant -> ParseError
constantValue :: Text,
Constant -> ParseError
constantCType :: Text,
Constant -> Documentation
constantDocumentation :: Documentation,
Constant -> Maybe DeprecationInfo
constantDeprecated :: Maybe DeprecationInfo
} deriving (Int -> Constant -> ShowS
[Constant] -> ShowS
Constant -> String
(Int -> Constant -> ShowS)
-> (Constant -> String) -> ([Constant] -> ShowS) -> Show Constant
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Constant -> ShowS
showsPrec :: Int -> Constant -> ShowS
$cshow :: Constant -> String
show :: Constant -> String
$cshowList :: [Constant] -> ShowS
showList :: [Constant] -> ShowS
Show)
parseConstant :: Parser (Name, Constant)
parseConstant :: Parser (Name, Constant)
parseConstant = do
name <- Parser Name
parseName
deprecated <- parseDeprecation
value <- getAttr "value"
t <- parseType
ctype <- queryAttrWithNamespace CGIRNS "type" >>= \case
Just ParseError
i -> ParseError -> Parser ParseError
forall a. a -> ReaderT ParseContext (Except ParseError) a
forall (m :: * -> *) a. Monad m => a -> m a
return ParseError
i
Maybe ParseError
Nothing -> GIRXMLNamespace -> Name -> Parser ParseError
getAttrWithNamespace GIRXMLNamespace
CGIRNS Name
"identifier"
doc <- parseDocumentation
return (name, Constant { constantType = t
, constantValue = value
, constantCType = ctype
, constantDocumentation = doc
, constantDeprecated = deprecated
})