module Data.GI.GIR.Property ( Property(..) , PropertyFlag(..) , parseProperty ) where import Data.Text (Text) #if !MIN_VERSION_base(4,11,0) import Data.Monoid ((<>)) #endif import Data.GI.GIR.Arg (parseTransfer) import Data.GI.GIR.BasicTypes (Transfer, Type) import Data.GI.GIR.Parser import Data.GI.GIR.Type (parseType) data PropertyFlag = PropertyReadable | PropertyWritable | PropertyConstruct | PropertyConstructOnly deriving (Int -> PropertyFlag -> ShowS [PropertyFlag] -> ShowS PropertyFlag -> String forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [PropertyFlag] -> ShowS $cshowList :: [PropertyFlag] -> ShowS show :: PropertyFlag -> String $cshow :: PropertyFlag -> String showsPrec :: Int -> PropertyFlag -> ShowS $cshowsPrec :: Int -> PropertyFlag -> ShowS Show,PropertyFlag -> PropertyFlag -> Bool forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: PropertyFlag -> PropertyFlag -> Bool $c/= :: PropertyFlag -> PropertyFlag -> Bool == :: PropertyFlag -> PropertyFlag -> Bool $c== :: PropertyFlag -> PropertyFlag -> Bool Eq) data Property = Property { Property -> ParseError propName :: Text, Property -> Type propType :: Type, Property -> [PropertyFlag] propFlags :: [PropertyFlag], Property -> Maybe Bool propReadNullable :: Maybe Bool, Property -> Maybe Bool propWriteNullable :: Maybe Bool, Property -> Transfer propTransfer :: Transfer, Property -> Documentation propDoc :: Documentation, Property -> Maybe DeprecationInfo propDeprecated :: Maybe DeprecationInfo } deriving (Int -> Property -> ShowS [Property] -> ShowS Property -> String forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [Property] -> ShowS $cshowList :: [Property] -> ShowS show :: Property -> String $cshow :: Property -> String showsPrec :: Int -> Property -> ShowS $cshowsPrec :: Int -> Property -> ShowS Show, Property -> Property -> Bool forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: Property -> Property -> Bool $c/= :: Property -> Property -> Bool == :: Property -> Property -> Bool $c== :: Property -> Property -> Bool Eq) parseProperty :: Parser Property parseProperty :: Parser Property parseProperty = do ParseError name <- Name -> Parser ParseError getAttr Name "name" Type t <- Parser Type parseType Transfer transfer <- Parser Transfer parseTransfer Maybe DeprecationInfo deprecated <- Parser (Maybe DeprecationInfo) parseDeprecation Bool readable <- forall a. Name -> a -> (ParseError -> Parser a) -> Parser a optionalAttr Name "readable" Bool True ParseError -> Parser Bool parseBool Bool writable <- forall a. Name -> a -> (ParseError -> Parser a) -> Parser a optionalAttr Name "writable" Bool False ParseError -> Parser Bool parseBool Bool construct <- forall a. Name -> a -> (ParseError -> Parser a) -> Parser a optionalAttr Name "construct" Bool False ParseError -> Parser Bool parseBool Bool constructOnly <- forall a. Name -> a -> (ParseError -> Parser a) -> Parser a optionalAttr Name "construct-only" Bool False ParseError -> Parser Bool parseBool Maybe Bool maybeNullable <- forall a. Name -> a -> (ParseError -> Parser a) -> Parser a optionalAttr Name "nullable" forall a. Maybe a Nothing (\ParseError t -> forall a. a -> Maybe a Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> ParseError -> Parser Bool parseBool ParseError t) let flags :: [PropertyFlag] flags = (if Bool readable then [PropertyFlag PropertyReadable] else []) forall a. Semigroup a => a -> a -> a <> (if Bool writable then [PropertyFlag PropertyWritable] else []) forall a. Semigroup a => a -> a -> a <> (if Bool construct then [PropertyFlag PropertyConstruct] else []) forall a. Semigroup a => a -> a -> a <> (if Bool constructOnly then [PropertyFlag PropertyConstructOnly] else []) Documentation doc <- Parser Documentation parseDocumentation forall (m :: * -> *) a. Monad m => a -> m a return forall a b. (a -> b) -> a -> b $ Property { propName :: ParseError propName = ParseError name , propType :: Type propType = Type t , propFlags :: [PropertyFlag] propFlags = [PropertyFlag] flags , propTransfer :: Transfer propTransfer = Transfer transfer , propDeprecated :: Maybe DeprecationInfo propDeprecated = Maybe DeprecationInfo deprecated , propDoc :: Documentation propDoc = Documentation doc , propReadNullable :: Maybe Bool propReadNullable = Maybe Bool maybeNullable , propWriteNullable :: Maybe Bool propWriteNullable = Maybe Bool maybeNullable }