forked from GitHub/gf-core
gf -cshell: implement visualize_tree
But the following options are not supported: -mk -nocats -nofuns
This commit is contained in:
@@ -16,11 +16,11 @@ import qualified PGF.Internal as H(Expr(EFun)) ----abstract,funs,cats,
|
|||||||
--import qualified PGF.Internal as H(optimizePGF)
|
--import qualified PGF.Internal as H(optimizePGF)
|
||||||
|
|
||||||
--import GF.Compile.Export
|
--import GF.Compile.Export
|
||||||
--import GF.Compile.ToAPI
|
import GF.Compile.ToAPI(exprToAPI)
|
||||||
--import GF.Compile.ExampleBased
|
--import GF.Compile.ExampleBased
|
||||||
--import GF.Infra.Option (noOptions, readOutputFormat, outputFormatsExpl)
|
--import GF.Infra.Option (noOptions, readOutputFormat, outputFormatsExpl)
|
||||||
--import GF.Infra.UseIO(writeUTF8File)
|
import GF.Infra.UseIO(writeUTF8File)
|
||||||
import GF.Infra.SIO(MonadSIO,liftSIO,putStrLn)
|
import GF.Infra.SIO(MonadSIO,liftSIO,putStrLn,restricted,restrictedSystem)
|
||||||
--import GF.Data.ErrM ----
|
--import GF.Data.ErrM ----
|
||||||
import GF.Command.Abstract
|
import GF.Command.Abstract
|
||||||
--import GF.Command.Messages
|
--import GF.Command.Messages
|
||||||
@@ -723,7 +723,7 @@ pgfCommands = Map.fromList [
|
|||||||
("leafedgestyle","edge style for links to leaves (solid/dashed/dotted/bold, default: dashed)")
|
("leafedgestyle","edge style for links to leaves (solid/dashed/dotted/bold, default: dashed)")
|
||||||
]
|
]
|
||||||
}),
|
}),
|
||||||
|
-}
|
||||||
("vt", emptyCommandInfo {
|
("vt", emptyCommandInfo {
|
||||||
longname = "visualize_tree",
|
longname = "visualize_tree",
|
||||||
synopsis = "show a set of trees graphically",
|
synopsis = "show a set of trees graphically",
|
||||||
@@ -733,21 +733,21 @@ pgfCommands = Map.fromList [
|
|||||||
"If the -view flag is defined, the graph is saved in a temporary file",
|
"If the -view flag is defined, the graph is saved in a temporary file",
|
||||||
"which is processed by graphviz and displayed by the program indicated",
|
"which is processed by graphviz and displayed by the program indicated",
|
||||||
"by the flag. The target format is postscript, unless overridden by the",
|
"by the flag. The target format is postscript, unless overridden by the",
|
||||||
"flag -format.",
|
"flag -format."--,
|
||||||
"With option -mk, use for showing library style function names of form 'mkC'."
|
-- "With option -mk, use for showing library style function names of form 'mkC'."
|
||||||
],
|
],
|
||||||
exec = \env@(pgf, mos) opts es ->
|
exec = needPGF $ \opts es env@(pgf, _) ->
|
||||||
if isOpt "mk" opts
|
{-if isOpt "mk" opts
|
||||||
then return $ fromString $ unlines $ map (tree2mk pgf) es
|
then return $ fromString $ unlines $ map (tree2mk pgf) es
|
||||||
else if isOpt "api" opts
|
else -}if isOpt "api" opts
|
||||||
then do
|
then do
|
||||||
let ss = map exprToAPI es
|
let ss = map exprToAPI es
|
||||||
mapM_ putStrLn ss
|
mapM_ putStrLn ss
|
||||||
return void
|
return void
|
||||||
else do
|
else do
|
||||||
let funs = not (isOpt "nofun" opts)
|
-- let funs = not (isOpt "nofun" opts)
|
||||||
let cats = not (isOpt "nocat" opts)
|
-- let cats = not (isOpt "nocat" opts)
|
||||||
let grph = unlines (map (H.graphvizAbstractTree pgf (funs,cats)) es) -- True=digraph
|
let grph = unlines (map (C.graphvizAbstractTree pgf . cExpr) es)
|
||||||
if isFlag "view" opts || isFlag "format" opts then do
|
if isFlag "view" opts || isFlag "format" opts then do
|
||||||
let file s = "_grph." ++ s
|
let file s = "_grph." ++ s
|
||||||
let view = optViewGraph opts
|
let view = optViewGraph opts
|
||||||
@@ -762,17 +762,16 @@ pgfCommands = Map.fromList [
|
|||||||
mkEx "p \"hello\" | vt -view=\"open\" -- parse a string and display trees on a Mac"
|
mkEx "p \"hello\" | vt -view=\"open\" -- parse a string and display trees on a Mac"
|
||||||
],
|
],
|
||||||
options = [
|
options = [
|
||||||
("api", "show the tree with function names converted to 'mkC' with value cats C"),
|
("api", "show the tree with function names converted to 'mkC' with value cats C")--,
|
||||||
("mk", "similar to -api, deprecated"),
|
-- ("mk", "similar to -api, deprecated"),
|
||||||
("nofun","don't show functions but only categories"),
|
-- ("nofun","don't show functions but only categories"),
|
||||||
("nocat","don't show categories but only functions")
|
-- ("nocat","don't show categories but only functions")
|
||||||
],
|
],
|
||||||
flags = [
|
flags = [
|
||||||
("format","format of the visualization file (default \"png\")"),
|
("format","format of the visualization file (default \"png\")"),
|
||||||
("view","program to open the resulting file (default \"open\")")
|
("view","program to open the resulting file (default \"open\")")
|
||||||
]
|
]
|
||||||
}),
|
}),
|
||||||
-}
|
|
||||||
|
|
||||||
("ai", emptyCommandInfo {
|
("ai", emptyCommandInfo {
|
||||||
longname = "abstract_info",
|
longname = "abstract_info",
|
||||||
@@ -978,9 +977,10 @@ pgfCommands = Map.fromList [
|
|||||||
Nothing -> error ("Can't parse '"++str++"' as a type")
|
Nothing -> error ("Can't parse '"++str++"' as a type")
|
||||||
|
|
||||||
optComm opts = valStrOpts "command" "" opts
|
optComm opts = valStrOpts "command" "" opts
|
||||||
|
-}
|
||||||
optViewFormat opts = valStrOpts "format" "png" opts
|
optViewFormat opts = valStrOpts "format" "png" opts
|
||||||
optViewGraph opts = valStrOpts "view" "open" opts
|
optViewGraph opts = valStrOpts "view" "open" opts
|
||||||
|
{-
|
||||||
optNum opts = valIntOpts "number" 1 opts
|
optNum opts = valIntOpts "number" 1 opts
|
||||||
-}
|
-}
|
||||||
optNumInf opts = valIntOpts "number" 1000000000 opts ---- 10^9
|
optNumInf opts = valIntOpts "number" 1000000000 opts ---- 10^9
|
||||||
|
|||||||
Reference in New Issue
Block a user