diff options
| author | aarne <aarne@cs.chalmers.se> | 2007-12-06 17:29:19 +0000 |
|---|---|---|
| committer | aarne <aarne@cs.chalmers.se> | 2007-12-06 17:29:19 +0000 |
| commit | fe30e3274872db43e96ed9db467e51f12f53effb (patch) | |
| tree | e782ed5cf1ad262c8cf1a3e9391d9405beb42b70 /src/GF/Devel/Grammar/Lookup.hs | |
| parent | bfd215aa7f79c97a5488349dc372f473950ea38d (diff) | |
in the middle of adapting CheckGrammar
Diffstat (limited to 'src/GF/Devel/Grammar/Lookup.hs')
| -rw-r--r-- | src/GF/Devel/Grammar/Lookup.hs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/GF/Devel/Grammar/Lookup.hs b/src/GF/Devel/Grammar/Lookup.hs index cb45b5406..3980577df 100644 --- a/src/GF/Devel/Grammar/Lookup.hs +++ b/src/GF/Devel/Grammar/Lookup.hs @@ -4,11 +4,13 @@ import GF.Devel.Grammar.Modules import GF.Devel.Grammar.Judgements import GF.Devel.Grammar.Macros import GF.Devel.Grammar.Terms +import GF.Devel.Grammar.PrGF import GF.Infra.Ident import GF.Data.Operations import Data.Map +import Data.List (sortBy) ---- -- look up fields for a constant in a grammar @@ -57,6 +59,22 @@ lookupParamValues gf m c = do V _ ts -> return ts _ -> raise "no parameter values" +allParamValues :: GF -> Type -> Err [Term] +allParamValues cnc ptyp = case ptyp of + App (Q (IC "Predef") (IC "Ints")) (EInt n) -> + return [EInt i | i <- [0..n]] + QC p c -> lookupParamValues cnc p c + Q p c -> lookupParamValues cnc p c ---- + RecType r -> do + let (ls,tys) = unzip $ sortByFst r + tss <- mapM allPV tys + return [R (zipAssign ls ts) | ts <- combinations tss] + _ -> prtBad "cannot find parameter values for" ptyp + where + allPV = allParamValues cnc + -- to normalize records and record types + sortByFst = sortBy (\ x y -> compare (fst x) (fst y)) + -- infrastructure for lookup lookupModule :: GF -> Ident -> Err Module |
