mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-22 19:22:50 -06:00
GFCC: TM with argument; fixed labels from bindings in gfc
This commit is contained in:
@@ -63,7 +63,7 @@ term2js l t = f t
|
|||||||
D.FV xs -> new "Variants" (map f xs)
|
D.FV xs -> new "Variants" (map f xs)
|
||||||
D.W str x -> new "Suffix" [JS.EStr str, f x]
|
D.W str x -> new "Suffix" [JS.EStr str, f x]
|
||||||
D.RP x y -> new "Rp" [f x, f y]
|
D.RP x y -> new "Rp" [f x, f y]
|
||||||
D.TM -> new "Meta" []
|
D.TM _ -> new "Meta" []
|
||||||
|
|
||||||
tokn2js :: D.Tokn -> JS.Expr
|
tokn2js :: D.Tokn -> JS.Expr
|
||||||
tokn2js (D.KS s) = mkStr s
|
tokn2js (D.KS s) = mkStr s
|
||||||
|
|||||||
@@ -459,7 +459,8 @@ term2term cgr env@(labels,untyps,typs) tr = case tr of
|
|||||||
Vr (IA (cat, _)) -> return (identC cat,[])
|
Vr (IA (cat, _)) -> return (identC cat,[])
|
||||||
Vr (IAV (cat,_,_)) -> return (identC cat,[])
|
Vr (IAV (cat,_,_)) -> return (identC cat,[])
|
||||||
Vr (IC s) -> return (identC cat,[]) where
|
Vr (IC s) -> return (identC cat,[]) where
|
||||||
cat = init (reverse (dropWhile (/='_') (reverse s))) ---- from gf parser
|
cat = takeWhile (/='_') s ---- also to match IAVs; no _ in a cat tolerated
|
||||||
|
---- init (reverse (dropWhile (/='_') (reverse s))) ---- from gf parser
|
||||||
---- Vr _ -> error $ "getLab " ++ show tr
|
---- Vr _ -> error $ "getLab " ++ show tr
|
||||||
P p lab2 -> do
|
P p lab2 -> do
|
||||||
(cat,labs) <- getLab p
|
(cat,labs) <- getLab p
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ inferTerm args trm = case trm of
|
|||||||
testErr (all (==typ) tys) ("different types in table " ++ show trm)
|
testErr (all (==typ) tys) ("different types in table " ++ show trm)
|
||||||
return (P t' u', typ) -- table: types must be same
|
return (P t' u', typ) -- table: types must be same
|
||||||
_ -> Bad $ "projection from " ++ show t ++ " : " ++ show tt
|
_ -> Bad $ "projection from " ++ show t ++ " : " ++ show tt
|
||||||
FV [] -> returnt TM ----
|
FV [] -> returnt tm0 ----
|
||||||
FV (t:ts) -> do
|
FV (t:ts) -> do
|
||||||
(t',ty) <- infer t
|
(t',ty) <- infer t
|
||||||
(ts',tys) <- mapM infer ts >>= return . unzip
|
(ts',tys) <- mapM infer ts >>= return . unzip
|
||||||
@@ -120,7 +120,7 @@ eqType :: CType -> CType -> Bool
|
|||||||
eqType inf exp = case (inf,exp) of
|
eqType inf exp = case (inf,exp) of
|
||||||
(C k, C n) -> k <= n -- only run-time corr.
|
(C k, C n) -> k <= n -- only run-time corr.
|
||||||
(R rs,R ts) -> length rs == length ts && and [eqType r t | (r,t) <- zip rs ts]
|
(R rs,R ts) -> length rs == length ts && and [eqType r t | (r,t) <- zip rs ts]
|
||||||
(TM, _) -> True ---- for variants [] ; not safe
|
(TM _, _) -> True ---- for variants [] ; not safe
|
||||||
_ -> inf == exp
|
_ -> inf == exp
|
||||||
|
|
||||||
-- should be in a generic module, but not in the run-time DataGFCC
|
-- should be in a generic module, but not in the run-time DataGFCC
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ data Term =
|
|||||||
| F CId
|
| F CId
|
||||||
| FV [Term]
|
| FV [Term]
|
||||||
| W String Term
|
| W String Term
|
||||||
| TM
|
| TM String
|
||||||
| RP Term Term
|
| RP Term Term
|
||||||
deriving (Eq,Ord,Show)
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
|
|||||||
@@ -23,11 +23,11 @@ realize trm = case trm of
|
|||||||
W s t -> s ++ realize t
|
W s t -> s ++ realize t
|
||||||
FV ts -> realize (ts !! 0) ---- other variants TODO
|
FV ts -> realize (ts !! 0) ---- other variants TODO
|
||||||
RP _ r -> realize r ---- DEPREC
|
RP _ r -> realize r ---- DEPREC
|
||||||
TM -> "?"
|
TM s -> s
|
||||||
_ -> "ERROR " ++ show trm ---- debug
|
_ -> "ERROR " ++ show trm ---- debug
|
||||||
|
|
||||||
linExp :: GFCC -> CId -> Exp -> Term
|
linExp :: GFCC -> CId -> Exp -> Term
|
||||||
linExp mcfg lang tree@(DTr xs at trees) = ---- bindings TODO
|
linExp mcfg lang tree@(DTr xs at trees) =
|
||||||
case at of
|
case at of
|
||||||
AC fun -> addB $ comp (lmap lin trees) $ look fun
|
AC fun -> addB $ comp (lmap lin trees) $ look fun
|
||||||
AS s -> R [kks (show s)] -- quoted
|
AS s -> R [kks (show s)] -- quoted
|
||||||
@@ -35,8 +35,8 @@ linExp mcfg lang tree@(DTr xs at trees) = ---- bindings TODO
|
|||||||
--- [C lst, kks (show i), C size] where
|
--- [C lst, kks (show i), C size] where
|
||||||
--- lst = mod (fromInteger i) 10 ; size = if i < 10 then 0 else 1
|
--- lst = mod (fromInteger i) 10 ; size = if i < 10 then 0 else 1
|
||||||
AF d -> R [kks (show d)]
|
AF d -> R [kks (show d)]
|
||||||
AV x -> addB $ R [kks (prCId x)] ---- lindef of cat
|
AV x -> addB $ TM (prCId x)
|
||||||
AM _ -> TM
|
AM i -> TM (show i)
|
||||||
where
|
where
|
||||||
lin = linExp mcfg lang
|
lin = linExp mcfg lang
|
||||||
comp = compute mcfg lang
|
comp = compute mcfg lang
|
||||||
@@ -63,7 +63,7 @@ compute mcfg lang args = comp where
|
|||||||
|
|
||||||
idx xs i = if i > length xs - 1
|
idx xs i = if i > length xs - 1
|
||||||
then trace
|
then trace
|
||||||
("too large " ++ show i ++ " for\n" ++ unlines (lmap show xs) ++ "\n") TM
|
("too large " ++ show i ++ " for\n" ++ unlines (lmap show xs) ++ "\n") tm0
|
||||||
else xs !! i
|
else xs !! i
|
||||||
|
|
||||||
proj r p = case (r,p) of
|
proj r p = case (r,p) of
|
||||||
@@ -79,12 +79,12 @@ compute mcfg lang args = comp where
|
|||||||
getIndex t = case t of
|
getIndex t = case t of
|
||||||
C i -> i
|
C i -> i
|
||||||
RP p _ -> getIndex p ---- DEPREC
|
RP p _ -> getIndex p ---- DEPREC
|
||||||
TM -> 0 -- default value for parameter
|
TM _ -> 0 -- default value for parameter
|
||||||
_ -> trace ("ERROR in grammar compiler: index from " ++ show t) 666
|
_ -> trace ("ERROR in grammar compiler: index from " ++ show t) 666
|
||||||
|
|
||||||
getField t i = case t of
|
getField t i = case t of
|
||||||
R rs -> idx rs i
|
R rs -> idx rs i
|
||||||
RP _ r -> getField r i ---- DEPREC
|
RP _ r -> getField r i ---- DEPREC
|
||||||
TM -> TM
|
TM s -> TM s
|
||||||
_ -> error ("ERROR in grammar compiler: field from " ++ show t) t
|
_ -> error ("ERROR in grammar compiler: field from " ++ show t) t
|
||||||
|
|
||||||
|
|||||||
@@ -12,19 +12,19 @@ import Data.List
|
|||||||
|
|
||||||
lookLin :: GFCC -> CId -> CId -> Term
|
lookLin :: GFCC -> CId -> CId -> Term
|
||||||
lookLin gfcc lang fun =
|
lookLin gfcc lang fun =
|
||||||
lookMap TM fun $ lins $ lookMap (error "no lang") lang $ concretes gfcc
|
lookMap tm0 fun $ lins $ lookMap (error "no lang") lang $ concretes gfcc
|
||||||
|
|
||||||
lookOper :: GFCC -> CId -> CId -> Term
|
lookOper :: GFCC -> CId -> CId -> Term
|
||||||
lookOper gfcc lang fun =
|
lookOper gfcc lang fun =
|
||||||
lookMap TM fun $ opers $ lookMap (error "no lang") lang $ concretes gfcc
|
lookMap tm0 fun $ opers $ lookMap (error "no lang") lang $ concretes gfcc
|
||||||
|
|
||||||
lookLincat :: GFCC -> CId -> CId -> Term
|
lookLincat :: GFCC -> CId -> CId -> Term
|
||||||
lookLincat gfcc lang fun =
|
lookLincat gfcc lang fun =
|
||||||
lookMap TM fun $ lincats $ lookMap (error "no lang") lang $ concretes gfcc
|
lookMap tm0 fun $ lincats $ lookMap (error "no lang") lang $ concretes gfcc
|
||||||
|
|
||||||
lookParamLincat :: GFCC -> CId -> CId -> Term
|
lookParamLincat :: GFCC -> CId -> CId -> Term
|
||||||
lookParamLincat gfcc lang fun =
|
lookParamLincat gfcc lang fun =
|
||||||
lookMap TM fun $ paramlincats $ lookMap (error "no lang") lang $ concretes gfcc
|
lookMap tm0 fun $ paramlincats $ lookMap (error "no lang") lang $ concretes gfcc
|
||||||
|
|
||||||
lookType :: GFCC -> CId -> Type
|
lookType :: GFCC -> CId -> Type
|
||||||
lookType gfcc f =
|
lookType gfcc f =
|
||||||
@@ -94,7 +94,10 @@ primNotion :: Exp
|
|||||||
primNotion = EEq []
|
primNotion = EEq []
|
||||||
|
|
||||||
term0 :: CId -> Term
|
term0 :: CId -> Term
|
||||||
term0 _ = TM
|
term0 = TM . prCId
|
||||||
|
|
||||||
|
tm0 :: Term
|
||||||
|
tm0 = TM "?"
|
||||||
|
|
||||||
kks :: String -> Term
|
kks :: String -> Term
|
||||||
kks = K . KS
|
kks = K . KS
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ toTerm e = case e of
|
|||||||
App (CId "A") [AInt i] -> V (fromInteger i)
|
App (CId "A") [AInt i] -> V (fromInteger i)
|
||||||
App f [] -> F f
|
App f [] -> F f
|
||||||
AInt i -> C (fromInteger i)
|
AInt i -> C (fromInteger i)
|
||||||
AMet -> TM
|
AMet -> TM "?"
|
||||||
AStr s -> K (KS s) ----
|
AStr s -> K (KS s) ----
|
||||||
_ -> error $ "term " ++ show e
|
_ -> error $ "term " ++ show e
|
||||||
|
|
||||||
@@ -202,7 +202,7 @@ fromTerm e = case e of
|
|||||||
RP e v -> app "RP" [fromTerm e, fromTerm v] ----
|
RP e v -> app "RP" [fromTerm e, fromTerm v] ----
|
||||||
W s v -> app "W" [AStr s, fromTerm v]
|
W s v -> app "W" [AStr s, fromTerm v]
|
||||||
C i -> AInt (toInteger i)
|
C i -> AInt (toInteger i)
|
||||||
TM -> AMet
|
TM _ -> AMet
|
||||||
F f -> App f []
|
F f -> App f []
|
||||||
V i -> App (CId "A") [AInt (toInteger i)]
|
V i -> App (CId "A") [AInt (toInteger i)]
|
||||||
K (KS s) -> AStr s ----
|
K (KS s) -> AStr s ----
|
||||||
|
|||||||
Reference in New Issue
Block a user