summaryrefslogtreecommitdiff
path: root/src/GF/Command/TreeOperations.hs
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2009-05-23 21:33:52 +0000
committerkrasimir <krasimir@chalmers.se>2009-05-23 21:33:52 +0000
commite5c8636a5f608af83d918e62533306cf7ddc7118 (patch)
tree813d9b452133b4283de850bd1d634f76678f46b8 /src/GF/Command/TreeOperations.hs
parent41b263cf6aa38e7c6ef090c0fa18949b86eec62c (diff)
now in the command shell the primary type in the pipe is Expr not Tree. This makes the pt -compute and pt -typecheck more interesting
Diffstat (limited to 'src/GF/Command/TreeOperations.hs')
-rw-r--r--src/GF/Command/TreeOperations.hs16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/GF/Command/TreeOperations.hs b/src/GF/Command/TreeOperations.hs
index ff87de563..262ce35b5 100644
--- a/src/GF/Command/TreeOperations.hs
+++ b/src/GF/Command/TreeOperations.hs
@@ -6,13 +6,9 @@ module GF.Command.TreeOperations (
import GF.Compile.TypeCheck
import PGF
---import GF.Compile.GrammarToGFCC (mkType,mkExp)
-import qualified GF.Grammar.Grammar as G
-import qualified GF.Grammar.Macros as M
-
import Data.List
-type TreeOp = [Tree] -> [Tree]
+type TreeOp = [Expr] -> [Expr]
treeOp :: PGF -> String -> Maybe TreeOp
treeOp pgf f = fmap snd $ lookup f $ allTreeOps pgf
@@ -20,20 +16,20 @@ treeOp pgf f = fmap snd $ lookup f $ allTreeOps pgf
allTreeOps :: PGF -> [(String,(String,TreeOp))]
allTreeOps pgf = [
("compute",("compute by using semantic definitions (def)",
- map (expr2tree pgf . tree2expr))),
+ map (compute pgf))),
("paraphrase",("paraphrase by using semantic definitions (def)",
- nub . concatMap (paraphrase pgf))),
+ map tree2expr . nub . concatMap (paraphrase pgf . expr2tree))),
("smallest",("sort trees from smallest to largest, in number of nodes",
smallest)),
("typecheck",("type check and solve metavariables; reject if incorrect",
concatMap (typecheck pgf)))
]
-smallest :: [Tree] -> [Tree]
+smallest :: [Expr] -> [Expr]
smallest = sortBy (\t u -> compare (size t) (size u)) where
size t = case t of
- Abs _ b -> size b + 1
- Fun f ts -> sum (map size ts) + 1
+ EAbs _ e -> size e + 1
+ EApp e1 e2 -> size e1 + size e2 + 1
_ -> 1
{-