{-# LANGUAGE CPP #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE ExplicitNamespaces #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Data.Name
(
Named
, nameOf
, nameProxy
, styleProxy
, SomeName(SomeName), viewSomeName
, HasName, myName
, NameStyle
, SomeNameStyle(SomeNameStyle), viewSomeNameStyle
, IsText(fromText)
, ConvertName(convertName)
, ConvertNameStyle(convertStyle)
, NameText, nameText
, UTF8
, type Name
, CaseInsensitive
, Secure
, SecureName, secureNameBypass
, HTMLStyle
, rawNamedHTML
, ValidNames, validName
, nameLength
, nullName
)
where
import Data.Hashable ( Hashable )
import Data.Proxy ( Proxy(Proxy) )
import Data.String ( IsString(fromString) )
import Data.Text ( Text )
import qualified Data.Text as T
import GHC.Exts ( Proxy#, proxy#, IsList(fromList, toList), Item )
import GHC.TypeLits
import Prettyprinter ( (<+>) )
import qualified Prettyprinter as PP
import Text.Sayable
#if !MIN_VERSION_base(4,16,0)
import Numeric.Natural
#endif
import Data.Name.Internal
nameOf :: KnownSymbol nameOf => Named style nameOf -> Proxy# nameOf -> String
nameOf :: forall (nameOf :: Symbol) (style :: Symbol).
KnownSymbol nameOf =>
Named style nameOf -> Proxy# nameOf -> String
nameOf Named style nameOf
_ = Proxy# nameOf -> String
forall (n :: Symbol). KnownSymbol n => Proxy# n -> String
symbolVal'
nameProxy :: KnownSymbol nameOf => Named style nameOf -> Proxy nameOf
nameProxy :: forall (nameOf :: Symbol) (style :: Symbol).
KnownSymbol nameOf =>
Named style nameOf -> Proxy nameOf
nameProxy Named style nameOf
_ = Proxy nameOf
forall {k} (t :: k). Proxy t
Proxy
styleProxy :: KnownSymbol style => Named style nameOf -> Proxy style
styleProxy :: forall (style :: Symbol) (nameOf :: Symbol).
KnownSymbol style =>
Named style nameOf -> Proxy style
styleProxy Named style nameOf
_ = Proxy style
forall {k} (t :: k). Proxy t
Proxy
instance {-# OVERLAPPABLE #-} IsString (Named style nameOf) where
fromString :: String -> Named style nameOf
fromString = Text -> Named style nameOf
forall (style :: Symbol) (nameOf :: Symbol).
Text -> Named style nameOf
Named (Text -> Named style nameOf)
-> (String -> Text) -> String -> Named style nameOf
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
forall a. IsString a => String -> a
fromString
class IsText a where fromText :: Text -> a
instance {-# OVERLAPPABLE #-} IsText (Named style nameOf) where
fromText :: Text -> Named style nameOf
fromText = Text -> Named style nameOf
forall (style :: Symbol) (nameOf :: Symbol).
Text -> Named style nameOf
Named
class NameText style => ConvertName style origTy newTy where
convertName :: Named style origTy -> Named style newTy
convertName = Text -> Named style newTy
forall a. IsText a => Text -> a
fromText (Text -> Named style newTy)
-> (Named style origTy -> Text)
-> Named style origTy
-> Named style newTy
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Named style origTy -> Text
forall (nm :: Symbol). Named style nm -> Text
forall (style :: Symbol) (nm :: Symbol).
NameText style =>
Named style nm -> Text
nameText
class ( NameText inpStyle
, IsText (Named outStyle nameTy)
)
=> ConvertNameStyle inpStyle outStyle nameTy where
convertStyle :: Named inpStyle nameTy -> Named outStyle nameTy
convertStyle = Text -> Named outStyle nameTy
forall a. IsText a => Text -> a
fromText (Text -> Named outStyle nameTy)
-> (Named inpStyle nameTy -> Text)
-> Named inpStyle nameTy
-> Named outStyle nameTy
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Named inpStyle nameTy -> Text
forall (nm :: Symbol). Named inpStyle nm -> Text
forall (style :: Symbol) (nm :: Symbol).
NameText style =>
Named style nm -> Text
nameText
class NameText style where
nameText :: Named style nm -> Text
nameText = Named style nm -> Text
forall (style :: Symbol) (nameOf :: Symbol).
Named style nameOf -> Text
named
class HasName x style nm | x -> style, x -> nm where
myName :: x -> Named style nm
instance NameText style => Sayable "info" (Named style nm) where
sayable :: Named style nm -> Saying "info"
sayable = Doc SayableAnn -> Saying "info"
forall (tag :: Symbol). Doc SayableAnn -> Saying tag
Saying (Doc SayableAnn -> Saying "info")
-> (Named style nm -> Doc SayableAnn)
-> Named style nm
-> Saying "info"
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Doc SayableAnn
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
PP.pretty (Text -> Doc SayableAnn)
-> (Named style nm -> Text) -> Named style nm -> Doc SayableAnn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Named style nm -> Text
forall (nm :: Symbol). Named style nm -> Text
forall (style :: Symbol) (nm :: Symbol).
NameText style =>
Named style nm -> Text
nameText
instance {-# OVERLAPPABLE #-} (PP.Pretty (Named style nm)
) => Sayable tag (Named style nm)
where sayable :: Named style nm -> Saying tag
sayable = Doc SayableAnn -> Saying tag
forall (tag :: Symbol). Doc SayableAnn -> Saying tag
Saying (Doc SayableAnn -> Saying tag)
-> (Named style nm -> Doc SayableAnn)
-> Named style nm
-> Saying tag
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Named style nm -> Doc SayableAnn
forall a ann. Pretty a => a -> Doc ann
forall ann. Named style nm -> Doc ann
PP.pretty
instance (Sayable "show" (Named style nm)) => Show (Named style nm) where
show :: Named style nm -> String
show = forall (saytag :: Symbol) a. Sayable saytag a => a -> String
sez @"show"
instance {-# OVERLAPPABLE #-} ( KnownSymbol ty
, NameText style
)
=> PP.Pretty (Named style ty) where
pretty :: forall ann. Named style ty -> Doc ann
pretty Named style ty
nm = (String -> Doc ann
forall ann. String -> Doc ann
forall a ann. Pretty a => a -> Doc ann
PP.pretty (String -> Doc ann) -> String -> Doc ann
forall a b. (a -> b) -> a -> b
$ Named style ty -> Proxy# ty -> String
forall (nameOf :: Symbol) (style :: Symbol).
KnownSymbol nameOf =>
Named style nameOf -> Proxy# nameOf -> String
nameOf Named style ty
nm Proxy# ty
forall {k} (a :: k). Proxy# a
proxy#)
Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann
PP.squotes (Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
PP.pretty (Named style ty -> Text
forall (nm :: Symbol). Named style nm -> Text
forall (style :: Symbol) (nm :: Symbol).
NameText style =>
Named style nm -> Text
nameText Named style ty
nm))
nameLength :: Named style nm -> Natural
nameLength :: forall (style :: Symbol) (nm :: Symbol). Named style nm -> Natural
nameLength = Int -> Natural
forall a. Enum a => Int -> a
toEnum (Int -> Natural)
-> (Named style nm -> Int) -> Named style nm -> Natural
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Int
T.length (Text -> Int) -> (Named style nm -> Text) -> Named style nm -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Named style nm -> Text
forall (style :: Symbol) (nameOf :: Symbol).
Named style nameOf -> Text
named
nullName :: Named style nm -> Bool
nullName :: forall (style :: Symbol) (nm :: Symbol). Named style nm -> Bool
nullName = Text -> Bool
T.null (Text -> Bool)
-> (Named style nm -> Text) -> Named style nm -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Named style nm -> Text
forall (style :: Symbol) (nameOf :: Symbol).
Named style nameOf -> Text
named
data SomeName =
forall (s :: Symbol) . KnownSymbol s => SomeName (Name s)
viewSomeName :: (forall (s :: Symbol) . KnownSymbol s => Name s -> r) -> SomeName -> r
viewSomeName :: forall r.
(forall (s :: Symbol). KnownSymbol s => Name s -> r)
-> SomeName -> r
viewSomeName forall (s :: Symbol). KnownSymbol s => Name s -> r
f (SomeName Name s
n) = Name s -> r
forall (s :: Symbol). KnownSymbol s => Name s -> r
f Name s
n
data SomeNameStyle nameTy =
forall (s :: Symbol)
. (KnownSymbol s, NameText s)
=> SomeNameStyle (Named s nameTy)
viewSomeNameStyle :: (forall (s :: Symbol) . (KnownSymbol s, NameText s) => Named s nameTy -> r)
-> SomeNameStyle nameTy -> r
viewSomeNameStyle :: forall (nameTy :: Symbol) r.
(forall (s :: Symbol).
(KnownSymbol s, NameText s) =>
Named s nameTy -> r)
-> SomeNameStyle nameTy -> r
viewSomeNameStyle forall (s :: Symbol).
(KnownSymbol s, NameText s) =>
Named s nameTy -> r
f (SomeNameStyle Named s nameTy
n) = Named s nameTy -> r
forall (s :: Symbol).
(KnownSymbol s, NameText s) =>
Named s nameTy -> r
f Named s nameTy
n
type UTF8 = "UTF8" :: NameStyle
type Name = Named UTF8
instance IsList (Name s) where
type Item (Name s) = Item Text
fromList :: [Item (Name s)] -> Name s
fromList = Text -> Name s
forall a. IsText a => Text -> a
fromText (Text -> Name s) -> (String -> Text) -> String -> Name s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
[Item Text] -> Text
forall l. IsList l => [Item l] -> l
fromList
toList :: Name s -> [Item (Name s)]
toList = Text -> String
Text -> [Item Text]
forall l. IsList l => l -> [Item l]
toList (Text -> String) -> (Name s -> Text) -> Name s -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name s -> Text
forall (nm :: Symbol). Named UTF8 nm -> Text
forall (style :: Symbol) (nm :: Symbol).
NameText style =>
Named style nm -> Text
nameText
instance ConvertName UTF8 a a where convertName :: Named UTF8 a -> Named UTF8 a
convertName = Named UTF8 a -> Named UTF8 a
forall a. a -> a
id
instance NameText UTF8
deriving instance Eq (Named UTF8 nameOf)
deriving instance Ord (Named UTF8 nameOf)
deriving instance Hashable (Named UTF8 nameOf)
type CaseInsensitive = "CaseInsensitive" :: NameStyle
instance {-# OVERLAPPING #-} IsString (Named CaseInsensitive nameOf) where
fromString :: String -> Named CaseInsensitive nameOf
fromString = Text -> Named CaseInsensitive nameOf
forall (style :: Symbol) (nameOf :: Symbol).
Text -> Named style nameOf
Named (Text -> Named CaseInsensitive nameOf)
-> (String -> Text) -> String -> Named CaseInsensitive nameOf
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
T.toLower (Text -> Text) -> (String -> Text) -> String -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
forall a. IsString a => String -> a
fromString
instance {-# OVERLAPPING #-} IsText (Named CaseInsensitive nameOf) where
fromText :: Text -> Named CaseInsensitive nameOf
fromText = Text -> Named CaseInsensitive nameOf
forall (style :: Symbol) (nameOf :: Symbol).
Text -> Named style nameOf
Named (Text -> Named CaseInsensitive nameOf)
-> (Text -> Text) -> Text -> Named CaseInsensitive nameOf
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
T.toLower
instance KnownSymbol ty => PP.Pretty (Named CaseInsensitive ty) where
pretty :: forall ann. Named CaseInsensitive ty -> Doc ann
pretty Named CaseInsensitive ty
nm = (String -> Doc ann
forall ann. String -> Doc ann
forall a ann. Pretty a => a -> Doc ann
PP.pretty (String -> Doc ann) -> String -> Doc ann
forall a b. (a -> b) -> a -> b
$ Named CaseInsensitive ty -> Proxy# ty -> String
forall (nameOf :: Symbol) (style :: Symbol).
KnownSymbol nameOf =>
Named style nameOf -> Proxy# nameOf -> String
nameOf Named CaseInsensitive ty
nm Proxy# ty
forall {k} (a :: k). Proxy# a
proxy#)
Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann -> Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann -> Doc ann
PP.surround (Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
PP.pretty (Named CaseInsensitive ty -> Text
forall (nm :: Symbol). Named CaseInsensitive nm -> Text
forall (style :: Symbol) (nm :: Symbol).
NameText style =>
Named style nm -> Text
nameText Named CaseInsensitive ty
nm)) Doc ann
"«" Doc ann
"»"
instance NameText CaseInsensitive
instance ConvertNameStyle UTF8 CaseInsensitive nameTy
deriving instance Eq (Named CaseInsensitive nameOf)
deriving instance Ord (Named CaseInsensitive nameOf)
deriving instance Hashable (Named CaseInsensitive nameOf)
type Secure = "SECURE!" :: NameStyle
type SecureName = Named Secure
secureName :: Named Secure nameOf -> Text
secureName :: forall (nameOf :: Symbol). Named Secure nameOf -> Text
secureName Named Secure nameOf
nm = if Text -> Int
T.length (Named Secure nameOf -> Text
forall (style :: Symbol) (nameOf :: Symbol).
Named style nameOf -> Text
named Named Secure nameOf
nm) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
5
then Int -> Text -> Text
T.replicate Int
8 Text
"#"
else ((Int -> Text -> Text
T.take Int
2 (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Named Secure nameOf -> Text
forall (style :: Symbol) (nameOf :: Symbol).
Named style nameOf -> Text
named Named Secure nameOf
nm)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text -> Text
T.replicate (Text -> Int
T.length (Named Secure nameOf -> Text
forall (style :: Symbol) (nameOf :: Symbol).
Named style nameOf -> Text
named Named Secure nameOf
nm) Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
4) Text
"#"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
T.reverse (Int -> Text -> Text
T.take Int
2 (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text -> Text
T.reverse (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Named Secure nameOf -> Text
forall (style :: Symbol) (nameOf :: Symbol).
Named style nameOf -> Text
named Named Secure nameOf
nm))
secureNameBypass :: Named Secure nameOf -> Text
secureNameBypass :: forall (nameOf :: Symbol). Named Secure nameOf -> Text
secureNameBypass = Named Secure nameOf -> Text
forall (style :: Symbol) (nameOf :: Symbol).
Named style nameOf -> Text
named
instance NameText Secure where
nameText :: forall (nameOf :: Symbol). Named Secure nameOf -> Text
nameText = Named Secure nm -> Text
forall (nameOf :: Symbol). Named Secure nameOf -> Text
secureName
deriving instance Eq (Named Secure nameOf)
deriving instance Ord (Named Secure nameOf)
deriving instance Hashable (Named Secure nameOf)
type HTMLStyle = "HTML" :: NameStyle
instance {-# OVERLAPPING #-} IsString (Named HTMLStyle nameOf) where
fromString :: String -> Named HTMLStyle nameOf
fromString = Text -> Named HTMLStyle nameOf
forall (style :: Symbol) (nameOf :: Symbol).
Text -> Named style nameOf
Named (Text -> Named HTMLStyle nameOf)
-> (String -> Text) -> String -> Named HTMLStyle nameOf
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
toHTMLSafe (Text -> Text) -> (String -> Text) -> String -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
forall a. IsString a => String -> a
fromString
instance {-# OVERLAPPING #-} IsText (Named HTMLStyle nameOf) where
fromText :: Text -> Named HTMLStyle nameOf
fromText = Text -> Named HTMLStyle nameOf
forall (style :: Symbol) (nameOf :: Symbol).
Text -> Named style nameOf
Named (Text -> Named HTMLStyle nameOf)
-> (Text -> Text) -> Text -> Named HTMLStyle nameOf
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
toHTMLSafe
instance KnownSymbol ty => PP.Pretty (Named HTMLStyle ty) where
pretty :: forall ann. Named HTMLStyle ty -> Doc ann
pretty = Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
PP.pretty (Text -> Doc ann)
-> (Named HTMLStyle ty -> Text) -> Named HTMLStyle ty -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Named HTMLStyle ty -> Text
forall (nm :: Symbol). Named HTMLStyle nm -> Text
forall (style :: Symbol) (nm :: Symbol).
NameText style =>
Named style nm -> Text
nameText
instance NameText HTMLStyle
rawNamedHTML :: Text -> Named HTMLStyle nameOf
rawNamedHTML :: forall (nameOf :: Symbol). Text -> Named HTMLStyle nameOf
rawNamedHTML = Text -> Named HTMLStyle nameOf
forall (style :: Symbol) (nameOf :: Symbol).
Text -> Named style nameOf
Named
toHTMLSafe :: Text -> Text
toHTMLSafe :: Text -> Text
toHTMLSafe = HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
T.replace Text
"<" Text
"<"
(Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
T.replace Text
">" Text
">"
(Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
T.replace Text
"\"" Text
"""
(Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
T.replace Text
"'" Text
"'"
(Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
T.replace Text
"&" Text
"&"
fromSafeHTML :: Text -> Text
fromSafeHTML :: Text -> Text
fromSafeHTML = HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
T.replace Text
"&" Text
"&"
(Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
T.replace Text
">" Text
">"
(Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
T.replace Text
"<" Text
"<"
(Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
T.replace Text
""" Text
"\""
(Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
T.replace Text
"'" Text
"'"
instance IsList (Named HTMLStyle s) where
type Item (Named HTMLStyle s) = Item Text
fromList :: [Item (Named HTMLStyle s)] -> Named HTMLStyle s
fromList = Text -> Named HTMLStyle s
forall a. IsText a => Text -> a
fromText (Text -> Named HTMLStyle s)
-> (String -> Text) -> String -> Named HTMLStyle s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
[Item Text] -> Text
forall l. IsList l => [Item l] -> l
fromList
toList :: Named HTMLStyle s -> [Item (Named HTMLStyle s)]
toList = Text -> String
Text -> [Item Text]
forall l. IsList l => l -> [Item l]
toList (Text -> String)
-> (Named HTMLStyle s -> Text) -> Named HTMLStyle s -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Named HTMLStyle s -> Text
forall (nm :: Symbol). Named HTMLStyle nm -> Text
forall (style :: Symbol) (nm :: Symbol).
NameText style =>
Named style nm -> Text
nameText
instance ConvertName HTMLStyle a a where convertName :: Named HTMLStyle a -> Named HTMLStyle a
convertName = Named HTMLStyle a -> Named HTMLStyle a
forall a. a -> a
id
instance ConvertNameStyle UTF8 HTMLStyle nameTy
instance ConvertNameStyle HTMLStyle UTF8 nameTy where
convertStyle :: Named HTMLStyle nameTy -> Named UTF8 nameTy
convertStyle = Text -> Named UTF8 nameTy
forall a. IsText a => Text -> a
fromText (Text -> Named UTF8 nameTy)
-> (Named HTMLStyle nameTy -> Text)
-> Named HTMLStyle nameTy
-> Named UTF8 nameTy
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
fromSafeHTML (Text -> Text)
-> (Named HTMLStyle nameTy -> Text)
-> Named HTMLStyle nameTy
-> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Named HTMLStyle nameTy -> Text
forall (nm :: Symbol). Named HTMLStyle nm -> Text
forall (style :: Symbol) (nm :: Symbol).
NameText style =>
Named style nm -> Text
nameText
deriving instance Eq (Named HTMLStyle nameOf)
deriving instance Ord (Named HTMLStyle nameOf)
deriving instance Hashable (Named HTMLStyle nameOf)
class ( KnownNat (AllowedNameType nameOf ntl)
, DisallowedNameType nameOf ntl ntl
)
=> ValidNames (nameOf :: Symbol) (ntl :: [Symbol]) where
validName :: Proxy ntl -> Name nameOf -> Text
instance ( KnownNat (AllowedNameType nty ntl)
, DisallowedNameType nty ntl ntl
)
=> ValidNames nty ntl where
validName :: Proxy ntl -> Name nty -> Text
validName Proxy ntl
_ = Name nty -> Text
forall (nm :: Symbol). Named UTF8 nm -> Text
forall (style :: Symbol) (nm :: Symbol).
NameText style =>
Named style nm -> Text
nameText
type family AllowedNameType (nty :: Symbol) (ntl :: [Symbol]) :: Nat where
AllowedNameType nty (nty ': ntl) = 0
AllowedNameType nty (any ': ntl) = 1 + (AllowedNameType nty ntl)
class DisallowedNameType (nty :: Symbol) (okntl :: [Symbol]) (ntl :: [Symbol])
instance TypeError ('Text "Name '" ':<>: 'ShowType nty
':<>: 'Text "' not in allowed Names: " ':<>: 'ShowType ntl)
=> DisallowedNameType nty '[] ntl
instance DisallowedNameType nty (nty ': ntys) ntl
instance {-# OVERLAPPABLE #-} DisallowedNameType nty ntys ntl
=> DisallowedNameType nty (oty ': ntys) ntl