summaryrefslogtreecommitdiff
path: root/src-3.0/GF/Command/Commands.hs
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2008-06-12 21:04:16 +0000
committeraarne <aarne@cs.chalmers.se>2008-06-12 21:04:16 +0000
commit3b15ade685f0281d67eba079391981a822e68a23 (patch)
tree802fff6c3ec1c60c9df6d9e721dacce45a6cb55c /src-3.0/GF/Command/Commands.hs
parent4369e679986fb602180b03f461105b9b3a2fdce2 (diff)
file name as option in commands
Diffstat (limited to 'src-3.0/GF/Command/Commands.hs')
-rw-r--r--src-3.0/GF/Command/Commands.hs25
1 files changed, 22 insertions, 3 deletions
diff --git a/src-3.0/GF/Command/Commands.hs b/src-3.0/GF/Command/Commands.hs
index 231f6db77..9ed57f376 100644
--- a/src-3.0/GF/Command/Commands.hs
+++ b/src-3.0/GF/Command/Commands.hs
@@ -200,9 +200,14 @@ allCommands pgf = Map.fromList [
("ps", emptyCommandInfo {
longname = "put_string",
synopsis = "return a string, possibly processed with a function",
- exec = \opts ->
- return . fromString . maybe id id (stringOp (concatMap prOpt opts)) . toString,
- flags = ["cat","lang"]
+ explanation = unlines [
+ "Returns a string obtained by its argument string by applying",
+ "string processing functions in the order given in the command line",
+ "option list. Thus 'ps -f -g s' returns g (f s). Typical string processors",
+ "are lexers and unlexers."
+ ],
+ exec = \opts -> return . fromString . stringOps opts . toString,
+ options = ["lextext","lexcode","lexmixed","unlextext","unlexcode","unlexmixed"]
}),
("q", emptyCommandInfo {
longname = "quit",
@@ -228,12 +233,22 @@ allCommands pgf = Map.fromList [
fromTrees [t | Just t <- [readExp s]]
_ | isOpt "lines" opts -> fromStrings $ lines s
_ -> fromString s
+ }),
+ ("wf", emptyCommandInfo {
+ longname = "write_file",
+ synopsis = "send string or tree to a file",
+ exec = \opts arg -> do
+ let file = valIdOpts "file" "_gftmp" opts
+ writeFile file (toString arg)
+ return void
})
]
where
lin opts t = unlines [linearize pgf lang t | lang <- optLangs opts]
par opts s = concat [parse pgf lang (optCat opts) s | lang <- optLangs opts]
+ void = ([],[])
+
optLin opts t = case opts of
_ | isOpt "treebank" opts -> unlines $ (abstractName pgf ++ ": " ++ showExp t) :
[lang ++ ": " ++ linea lang t | lang <- optLangs opts]
@@ -266,3 +281,7 @@ allCommands pgf = Map.fromList [
morphos opts s =
[lookupMorpho (buildMorpho pgf (mkCId la)) s | la <- optLangs opts]
+
+ -- ps -f -g s returns g (f s)
+ stringOps opts s = foldr app s (reverse (map prOpt opts)) where
+ app f = maybe id id (stringOp f)