concatenation string patterns

This commit is contained in:
aarne
2006-01-06 21:49:25 +00:00
parent 16dfdad304
commit 731aea1a03
7 changed files with 32 additions and 20 deletions

View File

@@ -10,6 +10,7 @@ resource Predef = {
oper Int : Type = variants {} ; -- the type of integers
oper Ints : Int -> Type = variants {} ; -- the type of integers from 0 to n
oper CC : Tok -> Tok -> Tok = variants {} ; -- concatenation; used in patterns
oper length : Tok -> Int = variants {} ; -- length of string
oper drop : Int -> Tok -> Tok = variants {} ; -- drop prefix of length
oper take : Int -> Tok -> Tok = variants {} ; -- take prefix of length

View File

@@ -195,25 +195,23 @@ resource ResGer = ParamGer ** open Prelude in {
VP : Type = {
s : Agr => VPForm => {
fin : Str ; -- V1 hat ---s1
inf : Str -- V2 gesagt ---s4
fin : Str ; -- V1 hat
inf : Str -- V2 gesagt
} ;
a1 : Polarity => Str ; -- A1 nicht ---s3
n2 : Agr => Str ; -- N2 dich ---s5
a2 : Str ; -- A2 heute ---s6
ext : Str -- S-Ext dass sie kommt ---s7
a1 : Polarity => Str ; -- A1 nicht
n2 : Agr => Str ; -- N2 dich
a2 : Str ; -- A2 heute
ext : Str -- S-Ext dass sie kommt
} ;
predV : Verb -> VP = \verb ->
let
vfin : Tense -> Agr -> Str = \t,a ->
verb.s ! vFin t a ;
vfin : Tense -> Agr -> Str = \t,a -> verb.s ! vFin t a ;
vpart = verb.s ! VPastPart APred ;
vinf = verb.s ! VInf ;
vHaben = auxPerfect verb ;
hat : Tense -> Agr -> Str = \t,a ->
vHaben ! vFin t a ;
hat : Tense -> Agr -> Str = \t,a -> vHaben ! vFin t a ;
haben : Str = vHaben ! VInf ;
wird : Agr -> Str = \a -> werden_V.s ! VPresInd a.n a.p ;
@@ -340,10 +338,6 @@ resource ResGer = ParamGer ** open Prelude in {
}
} ;
conjThat : Str = "daß" ;
conjThan : Str = "als" ;
reflPron : Agr => Str = table {
{n = Sg ; p = P1} => "mich" ;
{n = Sg ; p = P2} => "dich" ;
@@ -353,6 +347,11 @@ resource ResGer = ParamGer ** open Prelude in {
{n = Pl ; p = P3} => "sich"
} ;
conjThat : Str = "daß" ;
conjThan : Str = "als" ;
-- For $Numeral$.
--
-- mkNum : Str -> Str -> Str -> Str -> {s : DForm => CardOrd => Str} =

View File

@@ -664,7 +664,7 @@ checkLType env trm typ0 = do
pattContext :: LTEnv -> Type -> Patt -> Check Context
pattContext env typ p = case p of
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
(cont,v) <- checkErr $ typeFormCnc t
checkCond ("wrong number of arguments for constructor in" +++ prt p)

View File

@@ -221,14 +221,15 @@ renamePattern env patt = case patt of
PC c ps -> do
c' <- renameIdentTerm env $ Cn c
psvss <- mapM renp ps
let (ps',vs) = unzip psvss
case c' of
QC p d -> return (PP p d ps', concat vs)
Q p d -> return (PP p d ps', concat vs) ---- should not happen
QC p d -> renp $ PP p d ps
Q p d -> renp $ PP p d ps
_ -> 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
Ok p -> return (p,[])

View File

@@ -35,6 +35,7 @@ typPredefined c@(IC f) = case f of
"PBool" -> return typePType
"PFalse" -> return $ cnPredef "PBool"
"PTrue" -> return $ cnPredef "PBool"
"CC" -> return $ mkFunType [typeTok,typeTok] typeTok
"dp" -> return $ mkFunType [cnPredef "Int",typeTok] typeTok
"drop" -> return $ mkFunType [cnPredef "Int",typeTok] typeTok
"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
(z,_) <- appPredefined z0
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)
("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)

View File

@@ -66,6 +66,12 @@ tryMatch (p,t) = do
p `eqStrIdent` f && length pp == length tt ->
do matches <- mapM tryMatch (zip pp tt)
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)) |
-- q `eqStrIdent` r && --- not for inherited AR 10/10/2005
p `eqStrIdent` f && length pp == length tt ->
@@ -97,6 +103,7 @@ isInConstantForm trm = case trm of
App c a -> isInConstantForm c && isInConstantForm a
R r -> all (isInConstantForm . snd . snd) r
K _ -> True
Empty -> True
Alias _ _ t -> isInConstantForm t
EInt _ -> True
_ -> False ---- isInArgVarForm trm

View File

@@ -521,6 +521,8 @@ transPatts :: Patt -> Err [G.Patt]
transPatts p = case p of
PDisj p1 p2 -> liftM2 (++) (transPatts p1) (transPatts p2)
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
let (lss,ps) = unzip [(ls,p) | PA ls p <- pattasss]
ls = map LIdent $ concat lss