summaryrefslogtreecommitdiff
path: root/src/GF/UseGrammar/Editing.hs
diff options
context:
space:
mode:
authoraarne <unknown>2004-05-18 20:57:13 +0000
committeraarne <unknown>2004-05-18 20:57:13 +0000
commit8963681a3b821e85185877dd61b7804661fc5c24 (patch)
treefc2f4dee924cccd3d46c4983d80bc7b9a755ef41 /src/GF/UseGrammar/Editing.hs
parent086733a6fe03c5065002a8fb414af06c9cf67d51 (diff)
peel head i ; gt nometas ; gf2hs
Diffstat (limited to 'src/GF/UseGrammar/Editing.hs')
-rw-r--r--src/GF/UseGrammar/Editing.hs35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/GF/UseGrammar/Editing.hs b/src/GF/UseGrammar/Editing.hs
index 3c3567394..6f444efe8 100644
--- a/src/GF/UseGrammar/Editing.hs
+++ b/src/GF/UseGrammar/Editing.hs
@@ -40,6 +40,11 @@ actCat = errVal undefined . val2cat . actVal ---- undef
actAtom :: State -> Atom
actAtom = atomTree . actTree
+actFun :: State -> Err Fun
+actFun s = case actAtom s of
+ AtC f -> return f
+ t -> prtBad "active atom: expected function, found" t
+
actExp = tree2exp . actTree
-- current local bindings
@@ -319,10 +324,12 @@ changeFunHead gr f state = do
let state' = changeNode (changeAtom (const (atomC f))) state
reCheckState gr state' --- must be done because of constraints elsewhere
-peelFunHead :: CGrammar -> Action
-peelFunHead gr state = do
- state' <- forgetNode state
- reCheckState gr state' --- must be done because of constraints elsewhere
+peelFunHead :: CGrammar -> (Fun,Int) -> Action
+peelFunHead gr (f@(m,c),i) state = do
+ tree0 <- nthSubtree i $ actTree state
+ let tree = addBinds (actBinds state) $ tree0
+ state' <- replaceSubTree tree state
+ reCheckState gr state' --- must be unfortunately done. 20/11/2001
-- an expensive operation
reCheckState :: CGrammar -> State -> Err State
@@ -355,6 +362,20 @@ wrappingsState gr state
funs = funsOnType (possibleRefVal gr state) gr aval
aval = actVal state
+peelingsState :: CGrammar -> State -> [(Fun,Int)]
+peelingsState gr state
+ | actIsMeta state = []
+ | isRootState state =
+ err (const []) (\f -> [(f,i) | i <- [0 .. arityTree tree - 1]]) $ actFun state
+ | otherwise =
+ err (const [])
+ (\f -> [fi | (fi@(g,_),typ) <- funs,
+ possibleRefVal gr state aval typ,g==f]) $ actFun state
+ where
+ funs = funsOnType (possibleRefVal gr state) gr aval
+ aval = actVal state
+ tree = actTree state
+
headChangesState :: CGrammar -> State -> [Fun]
headChangesState gr state = errVal [] $ do
f@(m,c) <- funAtom (actAtom state)
@@ -362,12 +383,6 @@ headChangesState gr state = errVal [] $ do
return [fun | (fun,typ) <- funRulesOf gr, fun /= f, typ == typ0]
--- alpha-conv !
-canPeelState :: CGrammar -> State -> Bool
-canPeelState gr state = errVal False $ do
- f@(m,c) <- funAtom (actAtom state)
- typ <- lookupFunType gr m c
- return $ isInOneType typ
-
possibleRefVal :: CGrammar -> State -> Val -> Type -> Bool
possibleRefVal gr state val typ = errVal True $ do --- was False
vtyp <- valType typ