packages feed

css-parser-0.0.2 / src / CssParser / Ident.hs

module CssParser.Ident whereimport CssParser.Preludeimport CssParser.Showimport CssParser.Utils ( encodeIdentifier )import Data.Text (pack)data BrowserPrefix  = Moz  | Na  | Opera  | WebKit  | Apple  | Microsoft  deriving (Eq, Ord, Show, Bounded, Enum, Generic)bpLength :: BrowserPrefix -> IntbpLength = \case   Moz -> 5   Na -> 0   Opera -> 3   WebKit -> 8   Apple -> 7   Microsoft -> 4instance CssShow BrowserPrefix where  toCssText = \case    Moz -> "-moz-"    Na -> ""    Opera -> "-o-"    Apple -> "-apple-"    WebKit -> "-webkit-"    Microsoft -> "-ms-"newtype Ident = Ident Text  deriving newtype (Eq, Ord, Show, Semigroup, Monoid, IsString)  deriving (Generic)instance GEnum Ident where  genum = [Ident "a"]data TagName  = TagName Ident  | AmpersandTag  | AsteriskTag  | NoTag  deriving (Eq, Ord, Show, Generic)data Namespace  = NoBar  | NoNs  | AsteriskNs  | Namespace Ident  deriving (Eq, Ord, Show, Generic)data AttrName  = AttrName  { attrNs :: Namespace  , attrName :: Ident  } deriving (Eq, Ord, Show, Generic)instance CssShow AttrName where  toCssText (AttrName n (Ident e)) = toCssText n <> encodeIdentifier edata CaseSensetivity  = CaseSensetive  | CaseInsensetive  deriving (Eq, Ord, Show, Generic)instance CssShow CaseSensetivity where  toCssText = \case    CaseSensetive -> " s"    CaseInsensetive -> " i"newtype Var = Var Ident deriving newtype (Show, Eq, Ord, IsString) deriving (Generic)instance CssShow Var where  toCssText (Var i) = "--" <> toCssText idata PropertyName  = PropertyName Ident  | VarProp Var  deriving  (Eq, Ord, Show, Generic)instance IsString PropertyName where  fromString ('-':'-':v) = VarProp (Var . Ident $ pack v)  fromString o = PropertyName . Ident $ pack oinstance CssShow PropertyName where  toCssText = \case    PropertyName i -> toCssText i    VarProp v -> toCssText vinstance CssShow Namespace where  toCssText = \case    NoBar -> ""    NoNs  -> "|"    AsteriskNs -> "*|"    Namespace (Ident t) -> encodeIdentifier t <> "|"instance CssShow TagName where  toCssText = \case    NoTag -> ""    AsteriskTag -> "*"    AmpersandTag -> "&"    TagName (Ident lt) -> fromStrict ltinstance CssShow Ident where  toCssText (Ident i) = encodeIdentifier inewtype LayerName = LayerName Ident deriving newtype (Show, Eq, Ord, CssShow, IsString) deriving (Generic)instance ShowSpaceBetween LayerName LayerName where  cssSpace _ _ = ", "newtype Charset = Charset Text deriving newtype (Show, Eq, Ord, IsString) deriving (Generic)instance CssShow Charset where  toCssText (Charset cs) = encodeStringLiteral csnewtype CustomSelectorName = CustomSelectorName Ident  deriving (Show, Ord, Eq, Generic)instance CssShow CustomSelectorName where  toCssText (CustomSelectorName i) = ":" <> toCssText i