summaryrefslogtreecommitdiff
path: root/src/GF
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2007-11-28 08:44:04 +0000
committeraarne <aarne@cs.chalmers.se>2007-11-28 08:44:04 +0000
commit5b0f98f388886932597b656e58a6d215f274fddb (patch)
treeca942be55fd497c1bb3b7a564b63af0ff6eca308 /src/GF
parentba938b3530d2044de05569aa10b2139fc794ea8a (diff)
lookup modules
Diffstat (limited to 'src/GF')
-rw-r--r--src/GF/Devel/Modules.hs45
1 files 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
+