summaryrefslogtreecommitdiff
path: root/src/GF/Command/Commands.hs
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2008-10-05 19:49:26 +0000
committeraarne <aarne@cs.chalmers.se>2008-10-05 19:49:26 +0000
commit394050d9f7d90f5b7a5905175bd51733048bf481 (patch)
treeda2d73466dca0659d4fcd88bb4a9a9c06db5e745 /src/GF/Command/Commands.hs
parente88c7a28a7af9610117513fc543dc2cbfc7379b2 (diff)
added a command for tree operations and started a module for defining them
Diffstat (limited to 'src/GF/Command/Commands.hs')
-rw-r--r--src/GF/Command/Commands.hs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/GF/Command/Commands.hs b/src/GF/Command/Commands.hs
index baeb6ba41..27ac61c81 100644
--- a/src/GF/Command/Commands.hs
+++ b/src/GF/Command/Commands.hs
@@ -27,6 +27,8 @@ import GF.Command.Messages
import GF.Text.Lexing
import GF.Text.Transliterations
+import GF.Command.TreeOperations ---- temporary place for typecheck and compute
+
import GF.Data.Operations
import GF.Text.Coding
@@ -367,6 +369,23 @@ allCommands cod pgf = Map.fromList [
exec = \opts -> return . fromString . stringOps (map prOpt opts) . toString,
options = stringOpOptions
}),
+ ("pt", emptyCommandInfo {
+ longname = "put_tree",
+ syntax = "ps OPT? TREE",
+ synopsis = "return a tree, possibly processed with a function",
+ explanation = unlines [
+ "Returns a tree obtained from its argument tree by applying",
+ "tree processing functions in the order given in the command line",
+ "option list. Thus 'pt -f -g s' returns g (f s). Typical tree processors",
+ "are type checking and semantic computation."
+ ],
+ examples = [
+ "pt -compute (plus one two) -- compute value",
+ "p \"foo\" | pt -typecheck -- type check parse results"
+ ],
+ exec = \opts -> return . fromTrees . treeOps (map prOpt opts),
+ options = treeOpOptions
+ }),
("q", emptyCommandInfo {
longname = "quit",
synopsis = "exit GF interpreter"
@@ -588,6 +607,9 @@ allCommands cod pgf = Map.fromList [
stringOps opts s = foldr app s (reverse opts) where
app f = maybe id id (stringOp f)
+ treeOps opts s = foldr app s (reverse opts) where
+ app f = maybe id id (treeOp f)
+
showAsString t = case t of
Lit (LStr s) -> s
_ -> "\n" ++ showTree t --- newline needed in other cases than the first
@@ -619,6 +641,8 @@ stringOpOptions = [
("words","lexer that assumes tokens separated by spaces (default)")
]
+treeOpOptions = [(op,expl) | (op,(expl,_)) <- allTreeOps]
+
translationQuiz :: String -> PGF -> Language -> Language -> Category -> IO ()
translationQuiz cod pgf ig og cat = do
tts <- translationList pgf ig og cat infinity