1 {-# LANGUAGE UndecidableInstances #-}
2 {-# OPTIONS_GHC -fno-warn-orphans #-}
3 -- | Symantic for 'Account'.
4 module Hcompta.LCC.Sym.Account where
6 import Control.Applicative (Applicative(..))
8 import Data.Function (($), (.), id)
9 import Data.Functor (Functor(..), (<$>))
10 import Data.Maybe (Maybe(..))
11 import Data.Monoid (Monoid(..))
13 import Data.Type.Equality ((:~:)(Refl))
14 import Text.Show (Show(..))
15 import qualified Data.NonNull as NonNull
16 import qualified Data.Text as Text
17 import qualified Prelude ()
19 import Hcompta.LCC.Account
20 import Hcompta.LCC.Name
21 import Language.Symantic
22 import qualified Language.Symantic.Lib as Sym
24 -- * Class 'Sym_Account'
25 class Sym_Account term where
26 account :: Account -> term Account
27 default account :: Trans t term => Account -> t term Account
28 account = trans_lift . account
30 type instance Sym_of_Iface (Proxy Account) = Sym_Account
31 type instance TyConsts_of_Iface (Proxy Account) = Proxy Account ': TyConsts_imported_by (Proxy Account)
32 type instance TyConsts_imported_by (Proxy Account) =
37 instance Sym_Account HostI where
39 instance Sym_Account TextI where
40 account a = TextI $ \_p _v ->
42 instance (Sym_Account r1, Sym_Account r2) => Sym_Account (DupI r1 r2) where
43 account x = account x `DupI` account x
46 ( Read_TyNameR TyName cs rs
47 , Inj_TyConst cs Account
48 ) => Read_TyNameR TyName cs (Proxy Account ': rs) where
49 read_TyNameR _cs (TyName "Account") k = k (ty @Account)
50 read_TyNameR _rs raw k = read_TyNameR (Proxy @rs) raw k
51 instance Show_TyConst cs => Show_TyConst (Proxy Account ': cs) where
52 show_TyConst TyConstZ{} = "Account"
53 show_TyConst (TyConstS c) = show_TyConst c
55 instance Proj_TyFamC cs Sym.TyFam_MonoElement Account
57 instance -- Proj_TyConC
58 ( Proj_TyConst cs Account
59 , Proj_TyConsts cs (TyConsts_imported_by (Proxy Account))
60 ) => Proj_TyConC cs (Proxy Account) where
61 proj_TyConC _ (TyConst q :$ TyConst c)
62 | Just Refl <- eq_skind (kind_of_TyConst c) SKiType
63 , Just Refl <- proj_TyConst c (Proxy @Account)
65 _ | Just Refl <- proj_TyConst q (Proxy @Eq) -> Just TyCon
66 | Just Refl <- proj_TyConst q (Proxy @Show) -> Just TyCon
68 proj_TyConC _c _q = Nothing
69 data instance TokenT meta (ts::[*]) (Proxy Account)
70 = Token_Term_Account Account
71 deriving instance (Eq meta, Eq_Token meta ts) => Eq (TokenT meta ts (Proxy Account))
72 deriving instance (Show meta, Show_Token meta ts) => Show (TokenT meta ts (Proxy Account))
75 ( Inj_TyConst cs Account
76 -- , Inj_TyConst (TyConsts_of_Ifaces is) (->)
79 ) => CompileI cs is (Proxy Account) where
82 Token_Term_Account a -> k (ty @Account) $ TermO $ \_c -> account a
84 Inj_Token meta ts Account =>
85 TokenizeT meta ts (Proxy Account) where
87 instance -- Gram_Term_AtomsT
92 , Inj_Token meta ts Account
93 ) => Gram_Term_AtomsT meta ts (Proxy Account) g where
95 [ rule "term_account" $
97 (\a meta -> ProTok $ inj_EToken meta $ Token_Term_Account a)
101 g_account :: CF g Account
103 Account . NonNull.impureNonNull
104 <$> some (id <$ char '/' <*> g_account_section)
105 g_account_section :: CF g Account_Section
108 <$> some (choice $ unicat <$> [Unicat_Letter])