From 2c60a2d82a0d7b90924e7dbbcacf36afb8549d17 Mon Sep 17 00:00:00 2001 From: aarne Date: Thu, 23 Sep 2004 14:41:42 +0000 Subject: Ints n --- src/GF/Grammar/MMacros.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/GF/Grammar/MMacros.hs') diff --git a/src/GF/Grammar/MMacros.hs b/src/GF/Grammar/MMacros.hs index 15e9b3c45..617e76437 100644 --- a/src/GF/Grammar/MMacros.hs +++ b/src/GF/Grammar/MMacros.hs @@ -272,3 +272,15 @@ string2var :: String -> Ident string2var s = case s of c:'_':i -> identV (readIntArg i,[c]) --- _ -> zIdent s + +-- reindex variables so that they tell nesting depth level + +reindexTerm :: Term -> Term +reindexTerm = qualif (0,[]) where + qualif dg@(d,g) t = case t of + Abs x b -> let x' = ind x d in Abs x' $ qualif (d+1, (x,x'):g) b + Prod x a b -> let x' = ind x d in Prod x' (qualif dg a) $ qualif (d+1, (x,x'):g) b + Vr x -> Vr $ look x g + _ -> composSafeOp (qualif dg) t + look x = maybe x id . lookup x --- if x is not in scope it is unchanged + ind x d = identC $ prIdent x ++ "_" ++ show d -- cgit v1.2.3