{-# LANGUAGE UndecidableInstances #-} {-# OPTIONS_GHC -fno-warn-orphans #-} -- | Symantic for 'Text'. module Language.Symantic.Lib.Text where import Data.Proxy import Data.Text (Text) import qualified Data.Text as Text import Data.Type.Equality ((:~:)(Refl)) import Language.Symantic.Parsing import Language.Symantic.Typing import Language.Symantic.Compiling import Language.Symantic.Interpreting import Language.Symantic.Transforming.Trans -- * Class 'Sym_Text' class Sym_Text term where text :: Text -> term Text default text :: Trans t term => Text -> t term Text text = trans_lift . text type instance Sym_of_Iface (Proxy Text) = Sym_Text type instance Consts_of_Iface (Proxy Text) = Proxy Text ': Consts_imported_by Text type instance Consts_imported_by Text = [ Proxy Eq , Proxy Monoid , Proxy Ord , Proxy Show ] instance Sym_Text HostI where text = HostI instance Sym_Text TextI where text a = TextI $ \_p _v -> Text.pack (show a) instance (Sym_Text r1, Sym_Text r2) => Sym_Text (DupI r1 r2) where text x = text x `DupI` text x instance ( Read_TypeNameR Type_Name cs rs , Inj_Const cs Text ) => Read_TypeNameR Type_Name cs (Proxy Text ': rs) where read_typenameR _cs (Type_Name "Text") k = k (ty @Text) read_typenameR _rs raw k = read_typenameR (Proxy @rs) raw k instance Show_Const cs => Show_Const (Proxy Text ': cs) where show_const ConstZ{} = "Text" show_const (ConstS c) = show_const c instance -- Proj_ConC ( Proj_Const cs Text , Proj_Consts cs (Consts_imported_by Text) ) => Proj_ConC cs (Proxy Text) where proj_conC _ (TyConst q :$ TyConst c) | Just Refl <- eq_skind (kind_of_const c) SKiType , Just Refl <- proj_const c (Proxy @Text) = case () of _ | Just Refl <- proj_const q (Proxy @Eq) -> Just Con | Just Refl <- proj_const q (Proxy @Monoid) -> Just Con | Just Refl <- proj_const q (Proxy @Ord) -> Just Con | Just Refl <- proj_const q (Proxy @Show) -> Just Con _ -> Nothing proj_conC _c _q = Nothing data instance TokenT meta (ts::[*]) (Proxy Text) = Token_Term_Text Text deriving instance Eq_Token meta ts => Eq (TokenT meta ts (Proxy Text)) deriving instance Show_Token meta ts => Show (TokenT meta ts (Proxy Text)) instance -- CompileI Inj_Const (Consts_of_Ifaces is) Text => CompileI is (Proxy Text) where compileI tok _ctx k = case tok of Token_Term_Text i -> k (ty @Text) $ TermO $ \_c -> text i instance -- TokenizeT -- Inj_Token meta ts Text => TokenizeT meta ts (Proxy Text) instance Gram_Term_AtomsT meta ts (Proxy Text) g -- TODO