forked from GitHub/gf-core
concatenation string patterns
This commit is contained in:
@@ -664,7 +664,7 @@ checkLType env trm typ0 = do
|
|||||||
pattContext :: LTEnv -> Type -> Patt -> Check Context
|
pattContext :: LTEnv -> Type -> Patt -> Check Context
|
||||||
pattContext env typ p = case p of
|
pattContext env typ p = case p of
|
||||||
PV x -> return [(x,typ)]
|
PV x -> return [(x,typ)]
|
||||||
PP q c ps | q /= cPredef -> do
|
PP q c ps | q /= cPredef || prt c == "CC" -> do ---- why this /=? AR 6/1/2006
|
||||||
t <- checkErr $ lookupResType cnc q c
|
t <- checkErr $ lookupResType cnc q c
|
||||||
(cont,v) <- checkErr $ typeFormCnc t
|
(cont,v) <- checkErr $ typeFormCnc t
|
||||||
checkCond ("wrong number of arguments for constructor in" +++ prt p)
|
checkCond ("wrong number of arguments for constructor in" +++ prt p)
|
||||||
|
|||||||
@@ -221,14 +221,15 @@ renamePattern env patt = case patt of
|
|||||||
|
|
||||||
PC c ps -> do
|
PC c ps -> do
|
||||||
c' <- renameIdentTerm env $ Cn c
|
c' <- renameIdentTerm env $ Cn c
|
||||||
psvss <- mapM renp ps
|
|
||||||
let (ps',vs) = unzip psvss
|
|
||||||
case c' of
|
case c' of
|
||||||
QC p d -> return (PP p d ps', concat vs)
|
QC p d -> renp $ PP p d ps
|
||||||
Q p d -> return (PP p d ps', concat vs) ---- should not happen
|
Q p d -> renp $ PP p d ps
|
||||||
_ -> prtBad "unresolved pattern" c' ---- (PC c ps', concat vs)
|
_ -> prtBad "unresolved pattern" c' ---- (PC c ps', concat vs)
|
||||||
|
|
||||||
---- PP p c ps -> (PP p c ps',concat vs') where (ps',vs') = unzip $ map renp ps
|
PP p c ps -> do
|
||||||
|
psvss <- mapM renp ps
|
||||||
|
let (ps',vs) = unzip psvss
|
||||||
|
return (PP p c ps', concat vs)
|
||||||
|
|
||||||
PV x -> case renid patt of
|
PV x -> case renid patt of
|
||||||
Ok p -> return (p,[])
|
Ok p -> return (p,[])
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ typPredefined c@(IC f) = case f of
|
|||||||
"PBool" -> return typePType
|
"PBool" -> return typePType
|
||||||
"PFalse" -> return $ cnPredef "PBool"
|
"PFalse" -> return $ cnPredef "PBool"
|
||||||
"PTrue" -> return $ cnPredef "PBool"
|
"PTrue" -> return $ cnPredef "PBool"
|
||||||
|
"CC" -> return $ mkFunType [typeTok,typeTok] typeTok
|
||||||
"dp" -> return $ mkFunType [cnPredef "Int",typeTok] typeTok
|
"dp" -> return $ mkFunType [cnPredef "Int",typeTok] typeTok
|
||||||
"drop" -> return $ mkFunType [cnPredef "Int",typeTok] typeTok
|
"drop" -> return $ mkFunType [cnPredef "Int",typeTok] typeTok
|
||||||
"eqInt" -> return $ mkFunType [cnPredef "Int",cnPredef "Int"] (cnPredef "PBool")
|
"eqInt" -> return $ mkFunType [cnPredef "Int",cnPredef "Int"] (cnPredef "PBool")
|
||||||
@@ -73,6 +74,7 @@ appPredefined t = case t of
|
|||||||
App (Q (IC "Predef") (IC f)) z0 -> do
|
App (Q (IC "Predef") (IC f)) z0 -> do
|
||||||
(z,_) <- appPredefined z0
|
(z,_) <- appPredefined z0
|
||||||
case (f, norm z, norm x) of
|
case (f, norm z, norm x) of
|
||||||
|
("CC", K r, K s) -> retb $ K (r ++ s)
|
||||||
("drop", EInt i, K s) -> retb $ K (drop (fi i) s)
|
("drop", EInt i, K s) -> retb $ K (drop (fi i) s)
|
||||||
("take", EInt i, K s) -> retb $ K (take (fi i) s)
|
("take", EInt i, K s) -> retb $ K (take (fi i) s)
|
||||||
("tk", EInt i, K s) -> retb $ K (take (max 0 (length s - fi i)) s)
|
("tk", EInt i, K s) -> retb $ K (take (max 0 (length s - fi i)) s)
|
||||||
|
|||||||
@@ -66,6 +66,12 @@ tryMatch (p,t) = do
|
|||||||
p `eqStrIdent` f && length pp == length tt ->
|
p `eqStrIdent` f && length pp == length tt ->
|
||||||
do matches <- mapM tryMatch (zip pp tt)
|
do matches <- mapM tryMatch (zip pp tt)
|
||||||
return (concat matches)
|
return (concat matches)
|
||||||
|
|
||||||
|
(PP (IC "Predef") (IC "CC") [p1,p2], ([],K s, [])) -> do
|
||||||
|
let cuts = [splitAt n s | n <- [0 .. length s]]
|
||||||
|
matches <- checks [mapM tryMatch [(p1,K s1),(p2,K s2)] | (s1,s2) <- cuts]
|
||||||
|
return (concat matches)
|
||||||
|
|
||||||
(PP q p pp, ([], QC r f, tt)) |
|
(PP q p pp, ([], QC r f, tt)) |
|
||||||
-- q `eqStrIdent` r && --- not for inherited AR 10/10/2005
|
-- q `eqStrIdent` r && --- not for inherited AR 10/10/2005
|
||||||
p `eqStrIdent` f && length pp == length tt ->
|
p `eqStrIdent` f && length pp == length tt ->
|
||||||
@@ -97,6 +103,7 @@ isInConstantForm trm = case trm of
|
|||||||
App c a -> isInConstantForm c && isInConstantForm a
|
App c a -> isInConstantForm c && isInConstantForm a
|
||||||
R r -> all (isInConstantForm . snd . snd) r
|
R r -> all (isInConstantForm . snd . snd) r
|
||||||
K _ -> True
|
K _ -> True
|
||||||
|
Empty -> True
|
||||||
Alias _ _ t -> isInConstantForm t
|
Alias _ _ t -> isInConstantForm t
|
||||||
EInt _ -> True
|
EInt _ -> True
|
||||||
_ -> False ---- isInArgVarForm trm
|
_ -> False ---- isInArgVarForm trm
|
||||||
|
|||||||
@@ -521,6 +521,8 @@ transPatts :: Patt -> Err [G.Patt]
|
|||||||
transPatts p = case p of
|
transPatts p = case p of
|
||||||
PDisj p1 p2 -> liftM2 (++) (transPatts p1) (transPatts p2)
|
PDisj p1 p2 -> liftM2 (++) (transPatts p1) (transPatts p2)
|
||||||
PC id patts -> liftM (map (G.PC id) . combinations) $ mapM transPatts patts
|
PC id patts -> liftM (map (G.PC id) . combinations) $ mapM transPatts patts
|
||||||
|
PQC q id patts -> liftM (map (G.PP q id) . combinations) (mapM transPatts patts)
|
||||||
|
|
||||||
PR pattasss -> do
|
PR pattasss -> do
|
||||||
let (lss,ps) = unzip [(ls,p) | PA ls p <- pattasss]
|
let (lss,ps) = unzip [(ls,p) | PA ls p <- pattasss]
|
||||||
ls = map LIdent $ concat lss
|
ls = map LIdent $ concat lss
|
||||||
|
|||||||
Reference in New Issue
Block a user