From 5b0f98f388886932597b656e58a6d215f274fddb Mon Sep 17 00:00:00 2001 From: aarne Date: Wed, 28 Nov 2007 08:44:04 +0000 Subject: [PATCH] lookup modules --- src/GF/Devel/Modules.hs | 45 ++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/src/GF/Devel/Modules.hs b/src/GF/Devel/Modules.hs index 811f93899..bf45f86c3 100644 --- a/src/GF/Devel/Modules.hs +++ b/src/GF/Devel/Modules.hs @@ -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 +