diff options
| author | aarne <aarne@cs.chalmers.se> | 2007-05-15 16:35:13 +0000 |
|---|---|---|
| committer | aarne <aarne@cs.chalmers.se> | 2007-05-15 16:35:13 +0000 |
| commit | 035689f8c745a23c9a3a073d316adf82e5f7d00b (patch) | |
| tree | e1e8921cfd504dcddca5fa3fff5271598aa9b01f /src/GF/Compile/CheckGrammar.hs | |
| parent | 8af473a6f5e04ce2aaf74916d91866f1bdb62151 (diff) | |
started direct compiler from GF to GFCC
Diffstat (limited to 'src/GF/Compile/CheckGrammar.hs')
| -rw-r--r-- | src/GF/Compile/CheckGrammar.hs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/GF/Compile/CheckGrammar.hs b/src/GF/Compile/CheckGrammar.hs index 0c5e9ba01..262980eb9 100644 --- a/src/GF/Compile/CheckGrammar.hs +++ b/src/GF/Compile/CheckGrammar.hs @@ -364,6 +364,14 @@ checkReservedId x = let c = prt x in then checkWarn ("Warning: reserved word used as identifier:" +++ c) else return () +-- to normalize records and record types +labelIndex :: Type -> Label -> Int +labelIndex ty lab = case ty of + RecType ts -> maybe (error ("label index" +++ prt lab)) id $ lookup lab $ labs ts + _ -> error $ "label index" +++ prt ty + where + labs ts = zip (map fst (sortBy (\ x y -> compare (fst x) (fst y)) ts)) [0..] + -- the underlying algorithms inferLType :: SourceGrammar -> Term -> Check (Term, Type) @@ -426,10 +434,13 @@ inferLType gr trm = case trm of P t i -> do (t',ty) <- infer t --- ?? ty' <- comp ty - termWith (P t' i) $ checkErr $ case ty' of +----- let tr2 = PI t' i (labelIndex ty' i) + let tr2 = P t' i + termWith tr2 $ checkErr $ case ty' of RecType ts -> maybeErr ("unknown label" +++ prt i +++ "in" +++ prt ty') $ lookup i ts _ -> prtBad ("record type expected for" +++ prt t +++ "instead of") ty' + PI t i _ -> infer $ P t i R r -> do let (ls,fs) = unzip r |
