summaryrefslogtreecommitdiff
path: root/src/GF/Compile/GrammarToGFCC.hs
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2009-05-20 21:03:56 +0000
committerkrasimir <krasimir@chalmers.se>2009-05-20 21:03:56 +0000
commit7db4b641ce6abe90dd404459cd5eccb6e67f618c (patch)
treef708d2e7ed970d71655b66cac78c8b525b010cd9 /src/GF/Compile/GrammarToGFCC.hs
parent401dfc28d62584178c1187c92dece8dd0832dcb4 (diff)
refactor the PGF.Expr type and the evaluation of abstract expressions
Diffstat (limited to 'src/GF/Compile/GrammarToGFCC.hs')
-rw-r--r--src/GF/Compile/GrammarToGFCC.hs24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/GF/Compile/GrammarToGFCC.hs b/src/GF/Compile/GrammarToGFCC.hs
index 272692be7..e1c5b8fb7 100644
--- a/src/GF/Compile/GrammarToGFCC.hs
+++ b/src/GF/Compile/GrammarToGFCC.hs
@@ -68,9 +68,9 @@ canon2gfcc opts pars cgr@(M.MGrammar ((a,abm):cms)) =
abs = D.Abstr aflags funs cats catfuns
gflags = Map.empty
aflags = Map.fromList [(mkCId f,x) | (f,x) <- optionsPGF (M.flags abm)]
- mkDef pty = case pty of
- Just t -> mkExp t
- _ -> CM.primNotion
+
+ mkDef (Just eqs) = [C.Equ (map mkPatt ps) (mkExp e) | (ps,e) <- eqs]
+ mkDef Nothing = []
-- concretes
lfuns = [(f', (mkType ty, mkDef pty)) |
@@ -119,9 +119,7 @@ mkType t = case GM.typeForm t of
Ok (hyps,(_,cat),args) -> C.DTyp (mkContext hyps) (i2i cat) (map mkExp args)
mkExp :: A.Term -> C.Expr
-mkExp t = case t of
- A.Eqs eqs -> C.EEq [C.Equ (map mkPatt ps) (mkExp e) | (ps,e) <- eqs]
- _ -> case GM.termForm t of
+mkExp t = case GM.termForm t of
Ok (xs,c,args) -> mkAbs xs (mkApp c (map mkExp args))
where
mkAbs xs t = foldr (C.EAbs . i2i) t xs
@@ -134,11 +132,15 @@ mkExp t = case t of
K s -> C.ELit (C.LStr s)
Meta (MetaSymb i) -> C.EMeta i
_ -> C.EMeta 0
- mkPatt p = case p of
- A.PP _ c ps -> foldl C.EApp (C.EVar (i2i c)) (map mkPatt ps)
- A.PV x -> C.EVar (i2i x)
- A.PW -> C.EVar wildCId
- A.PInt i -> C.ELit (C.LInt i)
+
+mkPatt p = case p of
+ A.PP _ c ps -> C.PApp (i2i c) (map mkPatt ps)
+ A.PV x -> C.PVar (i2i x)
+ A.PW -> C.PWild
+ A.PInt i -> C.PLit (C.LInt i)
+ A.PFloat f -> C.PLit (C.LFlt f)
+ A.PString s -> C.PLit (C.LStr s)
+
mkContext :: A.Context -> [C.Hypo]
mkContext hyps = [C.Hyp (i2i x) (mkType ty) | (x,ty) <- hyps]