1
0
forked from GitHub/gf-core

some more command options and documentation

This commit is contained in:
aarne
2008-06-14 15:48:52 +00:00
parent 246f307b22
commit 7a065580d2
3 changed files with 73 additions and 28 deletions

View File

@@ -86,20 +86,42 @@ allCommands pgf = Map.fromList [
}), }),
("cc", emptyCommandInfo { ("cc", emptyCommandInfo {
longname = "compute_concrete", longname = "compute_concrete",
synopsis = "computes concrete syntax term using the source grammar", syntax = "cc (-all | -table | -unqual)? TERM",
explanation = "Compute a term by concrete syntax definitions. Uses the topmost\n"++ synopsis = "computes concrete syntax term using a source grammar",
"resource module (the last in listing by command po) to resolve\n"++ explanation = unlines [
"constant names.\n"++ "Compute TERM by concrete syntax definitions. Uses the topmost",
"N.B. You need the flag -retain when importing the grammar, if you want\n"++ "module (the last one imported) to resolve constant names.",
"the oper definitions to be retained after compilation; otherwise this\n"++ "N.B.1 You need the flag -retain when importing the grammar, if you want",
"command does not expand oper constants.\n"++ "the definitions to be retained after compilation.",
"N.B.' The resulting Term is not a term in the sense of abstract syntax,\n"++ "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-demanding command." "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 { ("e", emptyCommandInfo {
longname = "empty", longname = "empty",
synopsis = "empty the environment" 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 { ("gr", emptyCommandInfo {
longname = "generate_random", longname = "generate_random",
synopsis = "generate random trees in the current abstract syntax", synopsis = "generate random trees in the current abstract syntax",
@@ -124,25 +146,30 @@ allCommands pgf = Map.fromList [
("gt", emptyCommandInfo { ("gt", emptyCommandInfo {
longname = "generate_trees", longname = "generate_trees",
synopsis = "generates a list of trees, by default exhaustive", synopsis = "generates a list of trees, by default exhaustive",
explanation = "Generates all trees up to a given depth. If the depth is large,\n"++ explanation = unlines [
"a small -alts is recommended. If a Tree argument is given, the\n"++ "Generates all trees of a given category, with increasing depth.",
"command completes the Tree with values to the metavariables in\n"++ "By default, the depth is inlimited, but this can be changed by a flag."
"the tree.", ---- "If a Tree argument is given, thecommand completes the Tree with values",
---- "to the metavariables in the tree."
],
flags = [ flags = [
("cat","the generation category"), ("cat","the generation category"),
("depth","the maximum generation depth"), ("depth","the maximum generation depth"),
("number","the number of trees generated") ("number","the number of trees generated")
], ],
exec = \opts _ -> do exec = \opts _ -> do
let dp = return $ valIntOpts "depth" 4 opts let dp = return $ valIntOpts "depth" 999999 opts
let ts = generateAllDepth pgf (optCat opts) dp let ts = generateAllDepth pgf (optCat opts) dp
return $ fromTrees $ take (optNumInf opts) ts return $ fromTrees $ take (optNumInf opts) ts
}), }),
("h", emptyCommandInfo { ("h", emptyCommandInfo {
longname = "help", longname = "help",
syntax = "h (-full)? COMMAND?",
synopsis = "get description of a command, or a the full list of commands", 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"++ explanation = unlines [
"Without argument, shows the first lines of all paragraphs.", "Displays information concerning the COMMAND.",
"Without argument, shows the synopsis of all commands."
],
options = [ options = [
("full","give full information of the commands") ("full","give full information of the commands")
], ],
@@ -253,11 +280,15 @@ allCommands pgf = Map.fromList [
}), }),
("ph", emptyCommandInfo { ("ph", emptyCommandInfo {
longname = "print_history", longname = "print_history",
synopsis = "print readline history", synopsis = "print command history",
explanation = "Prints the commands issued during the GF session.\n"++ explanation = unlines [
"The result is readable by the eh command.\n"++ "Prints the commands issued during the GF session.",
"example:\n"++ "The result is readable by the eh command.",
" ph | wf foo.hist -- save the history into a file" "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 { ("ps", emptyCommandInfo {
longname = "put_string", longname = "put_string",

View File

@@ -6,7 +6,8 @@ module GF.Grammar.API (
checkTerm, checkTerm,
computeTerm, computeTerm,
showTerm, showTerm,
TermPrintStyle(..) TermPrintStyle(..),
pTermPrintStyle
) where ) where
import GF.Source.ParGF import GF.Source.ParGF
@@ -65,3 +66,10 @@ showTerm style t =
data TermPrintStyle = TermPrintTable | TermPrintAll | TermPrintUnqual | TermPrintDefault data TermPrintStyle = TermPrintTable | TermPrintAll | TermPrintUnqual | TermPrintDefault
deriving (Show,Eq) deriving (Show,Eq)
pTermPrintStyle s = case s of
"table" -> TermPrintTable
"all" -> TermPrintAll
"unqual" -> TermPrintUnqual
_ -> TermPrintDefault

View File

@@ -41,18 +41,21 @@ loop opts gfenv0 = do
setCompletionFunction (Just (wordCompletion (commandenv gfenv0))) setCompletionFunction (Just (wordCompletion (commandenv gfenv0)))
s <- fetchCommand (prompt env) s <- fetchCommand (prompt env)
let gfenv = gfenv0 {history = s : history gfenv0} let gfenv = gfenv0 {history = s : history gfenv0}
let loopNewCPU gfenv' = do cpu' <- getCPUTime let loopNewCPU gfenv' = do
putStrLnFlush (show ((cpu' - cputime gfenv') `div` 1000000000) ++ " msec") cpu' <- getCPUTime
loop opts $ gfenv' {cputime = cpu'} putStrLnFlush (show ((cpu' - cputime gfenv') `div` 1000000000) ++ " msec")
loop opts $ gfenv' {cputime = cpu'}
case words s of case words s of
-- special commands, requiring source grammar in env -- special commands, requiring source grammar in env
"!":ws -> do "!":ws -> do
system $ unwords ws system $ unwords ws
loopNewCPU gfenv loopNewCPU gfenv
"cc":ws -> do "cc":ws -> do
-- FIXME: add options parsing for cc arguments let
let (style,term) = (TermPrintDefault, ws) (style,term) = case ws of
case pTerm (unwords term) >>= checkTerm sgr >>= computeTerm sgr of ---- make pipable ('-':w):ws2 -> (pTermPrintStyle w, ws2)
_ -> (TermPrintDefault, ws)
case pTerm (unwords term) >>= checkTerm sgr >>= computeTerm sgr of ---- pipe!
Ok x -> putStrLn (showTerm style x) Ok x -> putStrLn (showTerm style x)
Bad s -> putStrLn s Bad s -> putStrLn s
loopNewCPU gfenv loopNewCPU gfenv
@@ -67,6 +70,9 @@ loop opts gfenv0 = do
"e":_ -> loopNewCPU $ gfenv { "e":_ -> loopNewCPU $ gfenv {
commandenv=env{multigrammar=emptyPGF}, sourcegrammar = emptyGrammar commandenv=env{multigrammar=emptyPGF}, sourcegrammar = emptyGrammar
} }
---- "eh":file:_ ->
"ph":_ -> mapM_ putStrLn (reverse (history gfenv0)) >> loopNewCPU gfenv "ph":_ -> mapM_ putStrLn (reverse (history gfenv0)) >> loopNewCPU gfenv
"q":_ -> putStrLn "See you." >> return gfenv "q":_ -> putStrLn "See you." >> return gfenv