summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Command/TreeOperations.hs
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2009-12-13 18:50:29 +0000
committerkrasimir <krasimir@chalmers.se>2009-12-13 18:50:29 +0000
commitf85232947e74ee7ef8c7b0ad2338212e7e68f1be (patch)
tree667b886a5e3a4b026a63d4e3597f32497d824761 /src/compiler/GF/Command/TreeOperations.hs
parentd88a865faff59c98fc91556ff8700b10ee5f2df8 (diff)
reorganize the directories under src, and rescue the JavaScript interpreter from deprecated
Diffstat (limited to 'src/compiler/GF/Command/TreeOperations.hs')
-rw-r--r--src/compiler/GF/Command/TreeOperations.hs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/compiler/GF/Command/TreeOperations.hs b/src/compiler/GF/Command/TreeOperations.hs
new file mode 100644
index 000000000..941f03782
--- /dev/null
+++ b/src/compiler/GF/Command/TreeOperations.hs
@@ -0,0 +1,32 @@
+module GF.Command.TreeOperations (
+ treeOp,
+ allTreeOps
+ ) where
+
+import PGF
+import PGF.Data
+import Data.List
+
+type TreeOp = [Expr] -> [Expr]
+
+treeOp :: PGF -> String -> Maybe (Either TreeOp (CId -> TreeOp))
+treeOp pgf f = fmap snd $ lookup f $ allTreeOps pgf
+
+allTreeOps :: PGF -> [(String,(String,Either TreeOp (CId -> TreeOp)))]
+allTreeOps pgf = [
+ ("compute",("compute by using semantic definitions (def)",
+ Left $ map (compute pgf))),
+ ("transfer",("syntactic transfer by applying function and computing",
+ Right $ \f -> map (compute pgf . EApp (EFun f)))),
+ ("paraphrase",("paraphrase by using semantic definitions (def)",
+ Left $ nub . concatMap (paraphrase pgf))),
+ ("smallest",("sort trees from smallest to largest, in number of nodes",
+ Left $ smallest))
+ ]
+
+smallest :: [Expr] -> [Expr]
+smallest = sortBy (\t u -> compare (size t) (size u)) where
+ size t = case t of
+ EAbs _ _ e -> size e + 1
+ EApp e1 e2 -> size e1 + size e2 + 1
+ _ -> 1