1
0
forked from GitHub/gf-core

lookup modules

This commit is contained in:
aarne
2007-11-28 08:44:04 +00:00
parent ba938b3530
commit 5b0f98f388

View File

@@ -3,6 +3,8 @@ module GF.Devel.Modules where
import GF.Grammar.Grammar
import GF.Infra.Ident
import GF.Data.Operations
import Data.Map
@@ -13,25 +15,42 @@ data GF = GF {
gfmodules :: Map Ident Module
}
emptyGF :: GF
emptyGF = GF Nothing [] empty empty
data Module = Module {
mtype :: ModuleType,
minterfaces :: [(Ident,Ident)], -- non-empty for functors
mof :: Ident, -- other for concrete, same for rest
minterfaces :: [(Ident,Ident)], -- non-empty for functors
mextends :: [(Ident,MInclude)],
mopens :: [(Ident,Ident)], -- used name, original name
minstances :: [(Ident,Ident)], -- non-empty for instantiations
mopens :: [(Ident,Ident)], -- used name, original name
mflags :: Map Ident String,
mjments :: Map Ident (Either Judgement Ident) -- def or indirection
}
emptyModule :: Ident -> Module
emptyModule m = Module MGrammar m [] [] [] [] empty empty
listJudgements :: Module -> [(Ident,Either Judgement Ident)]
listJudgements = assocs . mjments
data ModuleType =
MAbstract
| MConcrete Ident
| MConcrete
| MGrammar
data MInclude =
MIAll
| MIExcept [Ident]
| MIOnly [Ident]
data Judgement = Judgement {
jform :: JudgementForm,
jtype :: Type,
jdef :: Term,
jprintname :: Term
jform :: JudgementForm, -- cat fun oper param
jtype :: Type, -- context type type type
jdef :: Term, -- lindef def - values
jlin :: Term, -- lincat lin def constructors
jprintname :: Term -- printname printname - -
}
data JudgementForm =
@@ -40,3 +59,15 @@ data JudgementForm =
| JOper
| JParam
lookupIdent :: GF -> Ident -> Ident -> Err (Either Judgement Ident)
lookupIdent gf m c = do
mo <- maybe (Bad "module not found") return $ mlookup m (gfmodules gf)
maybe (Bad "constant not found") return $ mlookup c (mjments mo)
lookupJudgement :: GF -> Ident -> Ident -> Err Judgement
lookupJudgement gf m c = do
eji <- lookupIdent gf m c
either return (\n -> lookupJudgement gf n c) eji
mlookup = Data.Map.lookup