{-# options_haddock not-home #-}
module Myxine.Target (Target, attribute, tag, TargetFact(..), targetFacts) where
import Data.Hashable
import Data.Text (Text)
import qualified Data.Aeson as JSON
import Data.HashMap.Lazy (HashMap)
import qualified Data.HashMap.Lazy as HashMap
import GHC.Generics
data Target = Target
{ tagName :: Text
, attributes :: HashMap Text Text
} deriving (Eq, Ord, Show, Generic, JSON.FromJSON)
attribute :: Text -> Target -> Maybe Text
attribute name Target{attributes} = HashMap.lookup name attributes
{-# INLINE attribute #-}
tag :: Target -> Text
tag Target{tagName} = tagName
{-# INLINE tag #-}
data TargetFact
= HasTag !Text
| AttributeEquals !Text !Text
| Window
deriving (Eq, Ord, Show, Generic, Hashable)
targetFacts :: Target -> [TargetFact]
targetFacts Target{tagName, attributes} =
HasTag tagName : map (uncurry AttributeEquals) (HashMap.toList attributes)