mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-22 19:22:50 -06:00
restored "?" as system pipe command
This commit is contained in:
@@ -87,6 +87,20 @@ commandHelp full (co,info) = unlines $ [
|
|||||||
-- this list must no more be kept sorted by the command name
|
-- this list must no more be kept sorted by the command name
|
||||||
allCommands :: String -> PGF -> Map.Map String CommandInfo
|
allCommands :: String -> PGF -> Map.Map String CommandInfo
|
||||||
allCommands cod pgf = Map.fromList [
|
allCommands cod pgf = Map.fromList [
|
||||||
|
("!", emptyCommandInfo {
|
||||||
|
synopsis = "system command: escape to system shell",
|
||||||
|
syntax = "! SYSTEMCOMMAND",
|
||||||
|
examples = [
|
||||||
|
"! ls *.gf -- list all GF files in the working directory"
|
||||||
|
]
|
||||||
|
}),
|
||||||
|
("?", emptyCommandInfo {
|
||||||
|
synopsis = "system pipe: send value from previous command to a system command",
|
||||||
|
syntax = "? SYSTEMCOMMAND",
|
||||||
|
examples = [
|
||||||
|
"gt | l | ? wc -- generate, linearize, word-count"
|
||||||
|
]
|
||||||
|
}),
|
||||||
("cc", emptyCommandInfo {
|
("cc", emptyCommandInfo {
|
||||||
longname = "compute_concrete",
|
longname = "compute_concrete",
|
||||||
syntax = "cc (-all | -table | -unqual)? TERM",
|
syntax = "cc (-all | -table | -unqual)? TERM",
|
||||||
@@ -443,7 +457,7 @@ allCommands cod pgf = Map.fromList [
|
|||||||
("sp", emptyCommandInfo {
|
("sp", emptyCommandInfo {
|
||||||
longname = "system_pipe",
|
longname = "system_pipe",
|
||||||
synopsis = "send argument to a system command",
|
synopsis = "send argument to a system command",
|
||||||
syntax = "sp -command=\"SYSTEMCOMMAND\" STRING",
|
syntax = "sp -command=\"SYSTEMCOMMAND\", alt. ? SYSTEMCOMMAND",
|
||||||
exec = \opts arg -> do
|
exec = \opts arg -> do
|
||||||
let tmpi = "_tmpi" ---
|
let tmpi = "_tmpi" ---
|
||||||
let tmpo = "_tmpo"
|
let tmpo = "_tmpo"
|
||||||
@@ -456,7 +470,7 @@ allCommands cod pgf = Map.fromList [
|
|||||||
("command","the system command applied to the argument")
|
("command","the system command applied to the argument")
|
||||||
],
|
],
|
||||||
examples = [
|
examples = [
|
||||||
"ps -command=\"wc\" \"foo\"",
|
"sp -command=\"wc\" \"foo\"",
|
||||||
"gt | l | sp -command=\"grep \\\"who\\\"\" | sp -command=\"wc\""
|
"gt | l | sp -command=\"grep \\\"who\\\"\" | sp -command=\"wc\""
|
||||||
]
|
]
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -20,12 +20,18 @@ pCommandLine = RP.sepBy (RP.skipSpaces >> pPipe) (RP.skipSpaces >> RP.char ';')
|
|||||||
|
|
||||||
pPipe = RP.sepBy1 (RP.skipSpaces >> pCommand) (RP.skipSpaces >> RP.char '|')
|
pPipe = RP.sepBy1 (RP.skipSpaces >> pCommand) (RP.skipSpaces >> RP.char '|')
|
||||||
|
|
||||||
pCommand = do
|
pCommand = (do
|
||||||
cmd <- pIdent RP.<++ (RP.char '%' >> pIdent >>= return . ('%':))
|
cmd <- pIdent RP.<++ (RP.char '%' >> pIdent >>= return . ('%':))
|
||||||
RP.skipSpaces
|
RP.skipSpaces
|
||||||
opts <- RP.sepBy pOption RP.skipSpaces
|
opts <- RP.sepBy pOption RP.skipSpaces
|
||||||
arg <- pArgument
|
arg <- pArgument
|
||||||
return (Command cmd opts arg)
|
return (Command cmd opts arg)
|
||||||
|
)
|
||||||
|
RP.<++ (do
|
||||||
|
RP.char '?'
|
||||||
|
c <- pSystemCommand
|
||||||
|
return (Command "sp" [OFlag "command" (VStr c)] ANoArg)
|
||||||
|
)
|
||||||
|
|
||||||
pOption = do
|
pOption = do
|
||||||
RP.char '-'
|
RP.char '-'
|
||||||
@@ -47,3 +53,12 @@ pArgument =
|
|||||||
(fmap ATree (pTree False)
|
(fmap ATree (pTree False)
|
||||||
RP.<++
|
RP.<++
|
||||||
(RP.munch isSpace >> RP.char '%' >> fmap AMacro pIdent))
|
(RP.munch isSpace >> RP.char '%' >> fmap AMacro pIdent))
|
||||||
|
|
||||||
|
pSystemCommand =
|
||||||
|
RP.munch isSpace >> (
|
||||||
|
(RP.char '"' >> (RP.manyTill (pEsc RP.<++ RP.get) (RP.char '"')))
|
||||||
|
RP.<++
|
||||||
|
RP.many RP.get
|
||||||
|
)
|
||||||
|
where
|
||||||
|
pEsc = RP.char '\\' >> RP.get
|
||||||
|
|||||||
Reference in New Issue
Block a user