-- | Parsing of constants in GIR files.
module Data.GI.GIR.Constant
    ( Constant(..)
    , parseConstant
    ) where

import Data.Text (Text)

import Data.GI.GIR.BasicTypes (Type)
import Data.GI.GIR.Type (parseType, parseCType)
import Data.GI.GIR.Parser

-- | Info about a constant.
data Constant = Constant {
      Constant -> Type
constantType        :: Type,
      Constant -> Text
constantValue       :: Text,
      Constant -> Text
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
showList :: [Constant] -> ShowS
$cshowList :: [Constant] -> ShowS
show :: Constant -> String
$cshow :: Constant -> String
showsPrec :: Int -> Constant -> ShowS
$cshowsPrec :: Int -> Constant -> ShowS
Show)

-- | Parse a "constant" element from the GIR file.
parseConstant :: Parser (Name, Constant)
parseConstant :: Parser (Name, Constant)
parseConstant = do
  Name
name <- Parser Name
parseName
  Maybe DeprecationInfo
deprecated <- Parser (Maybe DeprecationInfo)
parseDeprecation
  Text
value <- Name -> Parser Text
getAttr "value"
  Type
t <- Parser Type
parseType
  Text
ctype <- Parser Text
parseCType
  Documentation
doc <- Parser Documentation
parseDocumentation
  (Name, Constant) -> Parser (Name, Constant)
forall (m :: * -> *) a. Monad m => a -> m a
return (Name
name, Constant :: Type
-> Text
-> Text
-> Documentation
-> Maybe DeprecationInfo
-> Constant
Constant { constantType :: Type
constantType = Type
t
                         , constantValue :: Text
constantValue = Text
value
                         , constantCType :: Text
constantCType = Text
ctype
                         , constantDocumentation :: Documentation
constantDocumentation = Documentation
doc
                         , constantDeprecated :: Maybe DeprecationInfo
constantDeprecated = Maybe DeprecationInfo
deprecated
                         })