mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 03:32:51 -06:00
pattern macros: oper f : pattern T = # p ; used as #f in patterns
This commit is contained in:
2
Makefile
2
Makefile
@@ -24,4 +24,4 @@ sdist:
|
|||||||
gf:
|
gf:
|
||||||
runghc Setup.hs build rgl-none
|
runghc Setup.hs build rgl-none
|
||||||
strip dist/build/gf/gf
|
strip dist/build/gf/gf
|
||||||
mv dist/build/gf/gf bin
|
|
||||||
|
|||||||
@@ -563,7 +563,7 @@ inferLType gr trm = case trm of
|
|||||||
t' <- justCheck t typeStr
|
t' <- justCheck t typeStr
|
||||||
aa' <- flip mapM aa (\ (c,v) -> do
|
aa' <- flip mapM aa (\ (c,v) -> do
|
||||||
c' <- justCheck c typeStr
|
c' <- justCheck c typeStr
|
||||||
v' <- justCheck v typeStrs
|
v' <- checks $ map (justCheck v) [typeStrs, EPattType typeStr]
|
||||||
return (c',v'))
|
return (c',v'))
|
||||||
return (Alts (t',aa'), typeStr)
|
return (Alts (t',aa'), typeStr)
|
||||||
|
|
||||||
@@ -607,7 +607,7 @@ inferLType gr trm = case trm of
|
|||||||
|
|
||||||
EPattType ty -> do
|
EPattType ty -> do
|
||||||
ty' <- justCheck ty typeType
|
ty' <- justCheck ty typeType
|
||||||
return (ty',typeType)
|
return (EPattType ty',typeType)
|
||||||
EPatt p -> do
|
EPatt p -> do
|
||||||
ty <- inferPatt p
|
ty <- inferPatt p
|
||||||
return (trm, EPattType ty)
|
return (trm, EPattType ty)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import GF.Grammar.AppPredefined
|
|||||||
import Data.List (nub,intersperse)
|
import Data.List (nub,intersperse)
|
||||||
import Control.Monad (liftM2, liftM)
|
import Control.Monad (liftM2, liftM)
|
||||||
|
|
||||||
----import Debug.Trace ----
|
---- import Debug.Trace ----
|
||||||
|
|
||||||
-- | computation of concrete syntax terms into normal form
|
-- | computation of concrete syntax terms into normal form
|
||||||
-- used mainly for partial evaluation
|
-- used mainly for partial evaluation
|
||||||
@@ -186,9 +186,10 @@ computeTermOpt rec gr = comput True where
|
|||||||
r <- composOp (comp g) t
|
r <- composOp (comp g) t
|
||||||
returnC r
|
returnC r
|
||||||
|
|
||||||
Alts _ -> do
|
Alts (d,aa) -> do
|
||||||
r <- composOp (comp g) t
|
d' <- comp g d
|
||||||
returnC r
|
aa' <- mapM (compInAlts g) aa
|
||||||
|
returnC (Alts (d',aa'))
|
||||||
|
|
||||||
-- remove empty
|
-- remove empty
|
||||||
C a b -> do
|
C a b -> do
|
||||||
@@ -363,7 +364,10 @@ computeTermOpt rec gr = comput True where
|
|||||||
---- return $ V ptyp ts -- to save space, just course of values
|
---- return $ V ptyp ts -- to save space, just course of values
|
||||||
return $ T (TComp ptyp) (zip ps' ts)
|
return $ T (TComp ptyp) (zip ps' ts)
|
||||||
_ -> do
|
_ -> do
|
||||||
cs' <- mapM (compBranch g) cs
|
ps0 <- mapM (compPatternMacro . fst) cs
|
||||||
|
cs' <- mapM (compBranch g) (zip ps0 (map snd cs))
|
||||||
|
|
||||||
|
---- cs' <- mapM (compBranch g) cs
|
||||||
return $ T i cs' -- happens with variable types
|
return $ T i cs' -- happens with variable types
|
||||||
_ -> comp g t
|
_ -> comp g t
|
||||||
|
|
||||||
@@ -399,6 +403,19 @@ computeTermOpt rec gr = comput True where
|
|||||||
cs' <- mapM (comp g) [(f v) | v <- cs]
|
cs' <- mapM (comp g) [(f v) | v <- cs]
|
||||||
return $ S (V i cs') e
|
return $ S (V i cs') e
|
||||||
|
|
||||||
|
compInAlts g (v,c) = do
|
||||||
|
v' <- comp g v
|
||||||
|
c' <- comp g c
|
||||||
|
c2 <- case c' of
|
||||||
|
EPatt p -> liftM Strs $ getPatts p
|
||||||
|
_ -> return c'
|
||||||
|
return (v',c2)
|
||||||
|
where
|
||||||
|
getPatts p = case p of
|
||||||
|
PAlt a b -> liftM2 (++) (getPatts a) (getPatts b)
|
||||||
|
PString s -> return [K s]
|
||||||
|
_ -> fail $ "not valid pattern in pre expression" +++ prt p
|
||||||
|
|
||||||
{- ----
|
{- ----
|
||||||
uncurrySelect g fs t v = do
|
uncurrySelect g fs t v = do
|
||||||
ts <- mapM (allParamValues gr . snd) fs
|
ts <- mapM (allParamValues gr . snd) fs
|
||||||
|
|||||||
@@ -736,6 +736,8 @@ mkAlts cs = case cs of
|
|||||||
return $ Strs $ as ++ bs
|
return $ Strs $ as ++ bs
|
||||||
PString s -> return $ Strs [K s]
|
PString s -> return $ Strs [K s]
|
||||||
PV x -> return (Vr x) --- for macros; not yet complete
|
PV x -> return (Vr x) --- for macros; not yet complete
|
||||||
|
PMacro x -> return (Vr x) --- for macros; not yet complete
|
||||||
|
PM m c -> return (Q m c) --- for macros; not yet complete
|
||||||
_ -> fail "no strs from pattern"
|
_ -> fail "no strs from pattern"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user