summaryrefslogtreecommitdiff
path: root/src-3.0
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2008-06-14 15:48:52 +0000
committeraarne <aarne@cs.chalmers.se>2008-06-14 15:48:52 +0000
commit7a065580d231a5c181442a63ca04f016e4ca6b7c (patch)
treeec1c31deb77bb9a2f546a863233ad0f3add53677 /src-3.0
parent246f307b22fb02ccc2bdd37520fdc330715d44ee (diff)
some more command options and documentation
Diffstat (limited to 'src-3.0')
-rw-r--r--src-3.0/GF/Command/Commands.hs73
-rw-r--r--src-3.0/GF/Grammar/API.hs10
-rw-r--r--src-3.0/GFI.hs18
3 files changed, 73 insertions, 28 deletions
diff --git a/src-3.0/GF/Command/Commands.hs b/src-3.0/GF/Command/Commands.hs
index 7886f487e..859e326ea 100644
--- a/src-3.0/GF/Command/Commands.hs
+++ b/src-3.0/GF/Command/Commands.hs
@@ -86,20 +86,42 @@ allCommands pgf = Map.fromList [
}),
("cc", emptyCommandInfo {
longname = "compute_concrete",
- synopsis = "computes concrete syntax term using the source grammar",
- explanation = "Compute a term by concrete syntax definitions. Uses the topmost\n"++
- "resource module (the last in listing by command po) to resolve\n"++
- "constant names.\n"++
- "N.B. You need the flag -retain when importing the grammar, if you want\n"++
- "the oper definitions to be retained after compilation; otherwise this\n"++
- "command does not expand oper constants.\n"++
- "N.B.' The resulting Term is not a term in the sense of abstract syntax,\n"++
- "and hence not a valid input to a Tree-demanding command."
+ syntax = "cc (-all | -table | -unqual)? TERM",
+ synopsis = "computes concrete syntax term using a source grammar",
+ explanation = unlines [
+ "Compute TERM by concrete syntax definitions. Uses the topmost",
+ "module (the last one imported) to resolve constant names.",
+ "N.B.1 You need the flag -retain when importing the grammar, if you want",
+ "the definitions to be retained after compilation.",
+ "N.B.2 The resulting term is not a tree in the sense of abstract syntax",
+ "and hence not a valid input to a Tree-expecting command."
+ ],
+ options = [
+ ("all","pick all strings (forms and variants) from records and tables"),
+ ("table","show all strings labelled by parameters"),
+ ("unqual","hide qualifying module names")
+ ]
}),
("e", emptyCommandInfo {
longname = "empty",
synopsis = "empty the environment"
}),
+{- ----
+ ("eh", emptyCommandInfo {
+ longname = "execute_history",
+ synopsis = "execute commands in a file",
+ explanation = unlines [
+ "Runs the sequence of GF commands from the lines of a file.",
+ "One way to produce such a file is the ph command."
+ ],
+ flags = [
+ ("file","the script file")
+ ],
+ examples = [
+ "eh -file=foo.gfs -- run the script in file foo.gfs"
+ ]
+ }),
+-}
("gr", emptyCommandInfo {
longname = "generate_random",
synopsis = "generate random trees in the current abstract syntax",
@@ -124,25 +146,30 @@ allCommands pgf = Map.fromList [
("gt", emptyCommandInfo {
longname = "generate_trees",
synopsis = "generates a list of trees, by default exhaustive",
- explanation = "Generates all trees up to a given depth. If the depth is large,\n"++
- "a small -alts is recommended. If a Tree argument is given, the\n"++
- "command completes the Tree with values to the metavariables in\n"++
- "the tree.",
+ explanation = unlines [
+ "Generates all trees of a given category, with increasing depth.",
+ "By default, the depth is inlimited, but this can be changed by a flag."
+ ---- "If a Tree argument is given, thecommand completes the Tree with values",
+ ---- "to the metavariables in the tree."
+ ],
flags = [
("cat","the generation category"),
("depth","the maximum generation depth"),
("number","the number of trees generated")
],
exec = \opts _ -> do
- let dp = return $ valIntOpts "depth" 4 opts
+ let dp = return $ valIntOpts "depth" 999999 opts
let ts = generateAllDepth pgf (optCat opts) dp
return $ fromTrees $ take (optNumInf opts) ts
}),
("h", emptyCommandInfo {
longname = "help",
+ syntax = "h (-full)? COMMAND?",
synopsis = "get description of a command, or a the full list of commands",
- explanation = "Displays the paragraph concerning the command from this help file.\n"++
- "Without argument, shows the first lines of all paragraphs.",
+ explanation = unlines [
+ "Displays information concerning the COMMAND.",
+ "Without argument, shows the synopsis of all commands."
+ ],
options = [
("full","give full information of the commands")
],
@@ -253,11 +280,15 @@ allCommands pgf = Map.fromList [
}),
("ph", emptyCommandInfo {
longname = "print_history",
- synopsis = "print readline history",
- explanation = "Prints the commands issued during the GF session.\n"++
- "The result is readable by the eh command.\n"++
- "example:\n"++
- " ph | wf foo.hist -- save the history into a file"
+ synopsis = "print command history",
+ explanation = unlines [
+ "Prints the commands issued during the GF session.",
+ "The result is readable by the eh command.",
+ "The result can be used as a script when starting GF."
+ ],
+ examples = [
+ "ph | wf -file=foo.gfs -- save the history into a file"
+ ]
}),
("ps", emptyCommandInfo {
longname = "put_string",
diff --git a/src-3.0/GF/Grammar/API.hs b/src-3.0/GF/Grammar/API.hs
index 6d14fbf3c..182b5e94e 100644
--- a/src-3.0/GF/Grammar/API.hs
+++ b/src-3.0/GF/Grammar/API.hs
@@ -6,7 +6,8 @@ module GF.Grammar.API (
checkTerm,
computeTerm,
showTerm,
- TermPrintStyle(..)
+ TermPrintStyle(..),
+ pTermPrintStyle
) where
import GF.Source.ParGF
@@ -65,3 +66,10 @@ showTerm style t =
data TermPrintStyle = TermPrintTable | TermPrintAll | TermPrintUnqual | TermPrintDefault
deriving (Show,Eq)
+pTermPrintStyle s = case s of
+ "table" -> TermPrintTable
+ "all" -> TermPrintAll
+ "unqual" -> TermPrintUnqual
+ _ -> TermPrintDefault
+
+
diff --git a/src-3.0/GFI.hs b/src-3.0/GFI.hs
index 681a54f39..e5352c30c 100644
--- a/src-3.0/GFI.hs
+++ b/src-3.0/GFI.hs
@@ -41,18 +41,21 @@ loop opts gfenv0 = do
setCompletionFunction (Just (wordCompletion (commandenv gfenv0)))
s <- fetchCommand (prompt env)
let gfenv = gfenv0 {history = s : history gfenv0}
- let loopNewCPU gfenv' = do cpu' <- getCPUTime
- putStrLnFlush (show ((cpu' - cputime gfenv') `div` 1000000000) ++ " msec")
- loop opts $ gfenv' {cputime = cpu'}
+ let loopNewCPU gfenv' = do
+ cpu' <- getCPUTime
+ putStrLnFlush (show ((cpu' - cputime gfenv') `div` 1000000000) ++ " msec")
+ loop opts $ gfenv' {cputime = cpu'}
case words s of
-- special commands, requiring source grammar in env
"!":ws -> do
system $ unwords ws
loopNewCPU gfenv
"cc":ws -> do
- -- FIXME: add options parsing for cc arguments
- let (style,term) = (TermPrintDefault, ws)
- case pTerm (unwords term) >>= checkTerm sgr >>= computeTerm sgr of ---- make pipable
+ let
+ (style,term) = case ws of
+ ('-':w):ws2 -> (pTermPrintStyle w, ws2)
+ _ -> (TermPrintDefault, ws)
+ case pTerm (unwords term) >>= checkTerm sgr >>= computeTerm sgr of ---- pipe!
Ok x -> putStrLn (showTerm style x)
Bad s -> putStrLn s
loopNewCPU gfenv
@@ -67,6 +70,9 @@ loop opts gfenv0 = do
"e":_ -> loopNewCPU $ gfenv {
commandenv=env{multigrammar=emptyPGF}, sourcegrammar = emptyGrammar
}
+
+ ---- "eh":file:_ ->
+
"ph":_ -> mapM_ putStrLn (reverse (history gfenv0)) >> loopNewCPU gfenv
"q":_ -> putStrLn "See you." >> return gfenv