mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
term macro help
This commit is contained in:
@@ -114,14 +114,21 @@ allCommands pgf = Map.fromList [
|
||||
}),
|
||||
("dt", emptyCommandInfo {
|
||||
longname = "define_tree",
|
||||
syntax = "dt IDENT (TREE | STRING)", -- | '<' COMMANDLINE)",
|
||||
syntax = "dt IDENT (TREE | STRING | \"<\" COMMANDLINE)",
|
||||
synopsis = "define a tree or string macro",
|
||||
explanation = unlines [
|
||||
"Defines IDENT as macro for TREE or STRING, until IDENT gets redefined.",
|
||||
-- "The defining value can also come from a command, preceded by '<'.",
|
||||
"The defining value can also come from a command, preceded by \"<\".",
|
||||
"If the command gives many values, the first one is selected.",
|
||||
"A use of the macro has the form %IDENT. Currently this use cannot be",
|
||||
"a subtree of another tree. This command must be a line of its own",
|
||||
"and thus cannot be a part of a pipe."
|
||||
],
|
||||
examples = [
|
||||
("dt ex \"hello world\" -- define ex as string"),
|
||||
("dt ex UseN man_N -- define ex as string"),
|
||||
("dt ex < p -cat=NP \"the man in the car\" -- define ex as parse result"),
|
||||
("l -lang=LangSwe %ex | ps -to_utf8 -- linearize the tree ex")
|
||||
]
|
||||
}),
|
||||
("e", emptyCommandInfo {
|
||||
|
||||
@@ -3,6 +3,7 @@ module GF.Command.Interpreter (
|
||||
mkCommandEnv,
|
||||
emptyCommandEnv,
|
||||
interpretCommandLine,
|
||||
interpretPipe,
|
||||
getCommandOp
|
||||
) where
|
||||
|
||||
@@ -36,15 +37,17 @@ interpretCommandLine :: CommandEnv -> String -> IO ()
|
||||
interpretCommandLine env line =
|
||||
case readCommandLine line of
|
||||
Just [] -> return ()
|
||||
Just pipes -> do res <- runInterruptibly (mapM_ interPipe pipes)
|
||||
Just pipes -> do res <- runInterruptibly (mapM_ (interpretPipe env) pipes)
|
||||
case res of
|
||||
Left ex -> putStrLnFlush (show ex)
|
||||
Right x -> return x
|
||||
Nothing -> putStrLnFlush "command not parsed"
|
||||
where
|
||||
interPipe cs = do
|
||||
(_,s) <- intercs ([],"") cs
|
||||
|
||||
interpretPipe env cs = do
|
||||
v@(_,s) <- intercs ([],"") cs
|
||||
putStrLnFlush s
|
||||
return v
|
||||
where
|
||||
intercs treess [] = return treess
|
||||
intercs (trees,_) (c:cs) = do
|
||||
treess2 <- interc trees c
|
||||
@@ -52,7 +55,7 @@ interpretCommandLine env line =
|
||||
interc es comm@(Command co _ arg) = case co of
|
||||
'%':f -> case Map.lookup f (commandmacros env) of
|
||||
Just css -> do
|
||||
mapM_ interPipe (appLine (getCommandArg env arg es) css)
|
||||
mapM_ (interpretPipe env) (appLine (getCommandArg env arg es) css)
|
||||
return ([],[]) ---- return ?
|
||||
_ -> do
|
||||
putStrLn $ "command macro " ++ co ++ " not interpreted"
|
||||
|
||||
Reference in New Issue
Block a user