mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-22 19:22:50 -06:00
eqStr ; pipe to system
This commit is contained in:
@@ -5,9 +5,9 @@
|
|||||||
-- Stability : (stable)
|
-- Stability : (stable)
|
||||||
-- Portability : (portable)
|
-- Portability : (portable)
|
||||||
--
|
--
|
||||||
-- > CVS $Date: 2005/06/26 20:40:33 $
|
-- > CVS $Date: 2005/10/06 14:21:34 $
|
||||||
-- > CVS $Author: aarne $
|
-- > CVS $Author: aarne $
|
||||||
-- > CVS $Revision: 1.12 $
|
-- > CVS $Revision: 1.13 $
|
||||||
--
|
--
|
||||||
-- Predefined function type signatures and definitions.
|
-- Predefined function type signatures and definitions.
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
@@ -71,7 +71,7 @@ appPredefined t = case t of
|
|||||||
-- two-place functions
|
-- two-place functions
|
||||||
App (Q (IC "Predef") (IC f)) z0 -> do
|
App (Q (IC "Predef") (IC f)) z0 -> do
|
||||||
(z,_) <- appPredefined z0
|
(z,_) <- appPredefined z0
|
||||||
case (f, z, x) of
|
case (f, norm z, norm x) of
|
||||||
("drop", EInt i, K s) -> retb $ K (drop i s)
|
("drop", EInt i, K s) -> retb $ K (drop i s)
|
||||||
("take", EInt i, K s) -> retb $ K (take i s)
|
("take", EInt i, K s) -> retb $ K (take i s)
|
||||||
("tk", EInt i, K s) -> retb $ K (take (max 0 (length s - i)) s)
|
("tk", EInt i, K s) -> retb $ K (take (max 0 (length s - i)) s)
|
||||||
@@ -102,6 +102,9 @@ appPredefined t = case t of
|
|||||||
where
|
where
|
||||||
retb t = return (t,True) -- no further computing needed
|
retb t = return (t,True) -- no further computing needed
|
||||||
retf t = return (t,False) -- must be computed further
|
retf t = return (t,False) -- must be computed further
|
||||||
|
norm t = case t of
|
||||||
|
Empty -> K []
|
||||||
|
_ -> t
|
||||||
|
|
||||||
-- read makes variables into constants
|
-- read makes variables into constants
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
-- Stability : (stable)
|
-- Stability : (stable)
|
||||||
-- Portability : (portable)
|
-- Portability : (portable)
|
||||||
--
|
--
|
||||||
-- > CVS $Date: 2005/10/06 10:02:33 $
|
-- > CVS $Date: 2005/10/06 14:21:34 $
|
||||||
-- > CVS $Author: aarne $
|
-- > CVS $Author: aarne $
|
||||||
-- > CVS $Revision: 1.44 $
|
-- > CVS $Revision: 1.45 $
|
||||||
--
|
--
|
||||||
-- GF shell command interpreter.
|
-- GF shell command interpreter.
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
@@ -313,7 +313,9 @@ execC co@(comm, opts0) sa@(sh@(st,(h,_,_,_)),a) = checkOptions st co >> case com
|
|||||||
CWriteFile file -> justOutputArg opts (writeFile file) sa
|
CWriteFile file -> justOutputArg opts (writeFile file) sa
|
||||||
CAppendFile file -> justOutputArg opts (appendFile file) sa
|
CAppendFile file -> justOutputArg opts (appendFile file) sa
|
||||||
CSpeakAloud -> justOutputArg opts (speechGenerate opts) sa
|
CSpeakAloud -> justOutputArg opts (speechGenerate opts) sa
|
||||||
CSystemCommand s -> justOutput opts (system s >> return ()) sa
|
CSystemCommand s -> case a of
|
||||||
|
AUnit -> justOutput opts (system s >> return ()) sa
|
||||||
|
_ -> systemArg opts a s sa
|
||||||
CPutString -> changeArg (opSS2CommandArg (optStringCommand opts gro)) sa
|
CPutString -> changeArg (opSS2CommandArg (optStringCommand opts gro)) sa
|
||||||
----- CShowTerm -> changeArg (opTS2CommandArg (optPrintTerm opts gro) . s2t) sa
|
----- CShowTerm -> changeArg (opTS2CommandArg (optPrintTerm opts gro) . s2t) sa
|
||||||
CGrep ms -> changeArg (AString . unlines . filter (grep ms) . lines . prCommandArg) sa
|
CGrep ms -> changeArg (AString . unlines . filter (grep ms) . lines . prCommandArg) sa
|
||||||
@@ -417,6 +419,16 @@ justOutputArg opts f sa@(st,a) = f (utf (prCommandArg a)) >> return (st, AUnit)
|
|||||||
justOutput :: Options -> IO () -> ShellIO
|
justOutput :: Options -> IO () -> ShellIO
|
||||||
justOutput opts = justOutputArg opts . const
|
justOutput opts = justOutputArg opts . const
|
||||||
|
|
||||||
|
systemArg :: Options -> CommandArg -> String -> ShellIO
|
||||||
|
systemArg _ cont syst sa = do
|
||||||
|
writeFile tmpi $ prCommandArg cont
|
||||||
|
system $ syst ++ " <" ++ tmpi ++ " >" ++ tmpo
|
||||||
|
s <- readFile tmpo
|
||||||
|
returnArg (AString s) sa
|
||||||
|
where
|
||||||
|
tmpi = "_tmpi" ---
|
||||||
|
tmpo = "_tmpo"
|
||||||
|
|
||||||
-- | type system for command arguments; instead of plain strings...
|
-- | type system for command arguments; instead of plain strings...
|
||||||
data CommandArg =
|
data CommandArg =
|
||||||
AError String
|
AError String
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
-- Stability : (stable)
|
-- Stability : (stable)
|
||||||
-- Portability : (portable)
|
-- Portability : (portable)
|
||||||
--
|
--
|
||||||
-- > CVS $Date: 2005/10/06 10:02:34 $
|
-- > CVS $Date: 2005/10/06 14:21:34 $
|
||||||
-- > CVS $Author: aarne $
|
-- > CVS $Author: aarne $
|
||||||
-- > CVS $Revision: 1.15 $
|
-- > CVS $Revision: 1.16 $
|
||||||
--
|
--
|
||||||
-- Help on shell commands. Generated from HelpFile by 'make help'.
|
-- Help on shell commands. Generated from HelpFile by 'make help'.
|
||||||
-- PLEASE DON'T EDIT THIS FILE.
|
-- PLEASE DON'T EDIT THIS FILE.
|
||||||
@@ -93,16 +93,19 @@ txtHelpFile =
|
|||||||
"\ndc, define_command Name Anything" ++
|
"\ndc, define_command Name Anything" ++
|
||||||
"\n Add a new defined command. The Name must star with '%'. Later," ++
|
"\n Add a new defined command. The Name must star with '%'. Later," ++
|
||||||
"\n if 'Name X' is used, it is replaced by Anything where #1 is replaced" ++
|
"\n if 'Name X' is used, it is replaced by Anything where #1 is replaced" ++
|
||||||
"\n by X. Currently at most one argument is possible. To see" ++
|
"\n by X. " ++
|
||||||
"\n definitions in scope, use help -defs." ++
|
"\n Restrictions: Currently at most one argument is possible, and a defined" ++
|
||||||
|
"\n command cannot appear in a pipe. " ++
|
||||||
|
"\n To see what definitions are in scope, use help -defs." ++
|
||||||
"\n examples:" ++
|
"\n examples:" ++
|
||||||
"\n dc %tnp p -cat=NP -lang=Eng #1 | l -lang=Swe -- translate NPs" ++
|
"\n dc %tnp p -cat=NP -lang=Eng #1 | l -lang=Swe -- translate NPs" ++
|
||||||
"\n %tnp \"this man\" | p -lang=Swe -- translate and parse" ++
|
"\n %tnp \"this man\" -- translate and parse" ++
|
||||||
"\n" ++
|
"\n" ++
|
||||||
"\ndt, define_term Name Tree" ++
|
"\ndt, define_term Name Tree" ++
|
||||||
"\n Add a constant for a tree. The constant can later be called by" ++
|
"\n Add a constant for a tree. The constant can later be called by" ++
|
||||||
"\n prefixing it with '$'. It is not yet usable as a subterm. To see" ++
|
"\n prefixing it with '$'. " ++
|
||||||
"\n definitions in scope, use help -defs." ++
|
"\n Restriction: These terms are not yet usable as a subterm. " ++
|
||||||
|
"\n To see what definitions are in scope, use help -defs." ++
|
||||||
"\n examples:" ++
|
"\n examples:" ++
|
||||||
"\n p -cat=NP \"this man\" | dt tm -- define tm as parse result" ++
|
"\n p -cat=NP \"this man\" | dt tm -- define tm as parse result" ++
|
||||||
"\n l -all $tm -- linearize tm in all forms" ++
|
"\n l -all $tm -- linearize tm in all forms" ++
|
||||||
@@ -476,6 +479,12 @@ txtHelpFile =
|
|||||||
"\n example:" ++
|
"\n example:" ++
|
||||||
"\n ! ls" ++
|
"\n ! ls" ++
|
||||||
"\n" ++
|
"\n" ++
|
||||||
|
"\n?, system_command: ? String" ++
|
||||||
|
"\n Issues a system command that receives its arguments from GF pipe" ++
|
||||||
|
"\n and returns a value to GF." ++
|
||||||
|
"\n example:" ++
|
||||||
|
"\n h | ? 'wc -l' | p -cat=Num" ++
|
||||||
|
"\n" ++
|
||||||
"\n" ++
|
"\n" ++
|
||||||
"\n-- Flags. The availability of flags is defined separately for each command." ++
|
"\n-- Flags. The availability of flags is defined separately for each command." ++
|
||||||
"\n" ++
|
"\n" ++
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
-- Stability : (stable)
|
-- Stability : (stable)
|
||||||
-- Portability : (portable)
|
-- Portability : (portable)
|
||||||
--
|
--
|
||||||
-- > CVS $Date: 2005/10/06 10:02:34 $
|
-- > CVS $Date: 2005/10/06 14:21:34 $
|
||||||
-- > CVS $Author: aarne $
|
-- > CVS $Author: aarne $
|
||||||
-- > CVS $Revision: 1.27 $
|
-- > CVS $Revision: 1.28 $
|
||||||
--
|
--
|
||||||
-- parsing GF shell commands. AR 11\/11\/2001
|
-- parsing GF shell commands. AR 11\/11\/2001
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
@@ -62,6 +62,7 @@ unquote (x:xs@(_:_)) | x `elem` "\"'" && x == last xs = init xs
|
|||||||
unquote s = s
|
unquote s = s
|
||||||
|
|
||||||
pCommandLine :: HState -> [String] -> CommandLine
|
pCommandLine :: HState -> [String] -> CommandLine
|
||||||
|
pCommandLine st (c@('%':_):args) = pCommandLine st $ resolveShMacro st c args
|
||||||
pCommandLine st (dc:c:def) | abbrevCommand dc == "dc" = ((CDefineCommand c def, noOptions),AUnit,[])
|
pCommandLine st (dc:c:def) | abbrevCommand dc == "dc" = ((CDefineCommand c def, noOptions),AUnit,[])
|
||||||
pCommandLine st s = pFirst (chks s) where
|
pCommandLine st s = pFirst (chks s) where
|
||||||
pFirst cos = case cos of
|
pFirst cos = case cos of
|
||||||
@@ -73,7 +74,6 @@ pCommandLine st s = pFirst (chks s) where
|
|||||||
chks = map (pCommandOpt st) . chunks "|"
|
chks = map (pCommandOpt st) . chunks "|"
|
||||||
|
|
||||||
pCommandOpt :: HState -> [String] -> (Command, Options, [CommandArg])
|
pCommandOpt :: HState -> [String] -> (Command, Options, [CommandArg])
|
||||||
pCommandOpt st (c@('%':_):args) = pCommandOpt st $ resolveShMacro st c args
|
|
||||||
pCommandOpt _ (w:ws) = let
|
pCommandOpt _ (w:ws) = let
|
||||||
(os, co) = getOptions "-" ws
|
(os, co) = getOptions "-" ws
|
||||||
(comm, args) = pCommand (abbrevCommand w:co)
|
(comm, args) = pCommand (abbrevCommand w:co)
|
||||||
@@ -136,6 +136,7 @@ pCommand ws = case ws of
|
|||||||
"ps" : s -> aString CPutString s
|
"ps" : s -> aString CPutString s
|
||||||
"st" : s -> aTerm CShowTerm s
|
"st" : s -> aTerm CShowTerm s
|
||||||
"!" : s -> aUnit (CSystemCommand (unwords s))
|
"!" : s -> aUnit (CSystemCommand (unwords s))
|
||||||
|
"?" : s : x -> aString (CSystemCommand (unquote s)) x
|
||||||
"sc" : s -> aUnit (CSystemCommand (unwords s))
|
"sc" : s -> aUnit (CSystemCommand (unwords s))
|
||||||
"g" : f : s -> aString (CGrep (unquote f)) s
|
"g" : f : s -> aString (CGrep (unquote f)) s
|
||||||
|
|
||||||
|
|||||||
19
src/HelpFile
19
src/HelpFile
@@ -64,16 +64,19 @@ s, strip: s
|
|||||||
dc, define_command Name Anything
|
dc, define_command Name Anything
|
||||||
Add a new defined command. The Name must star with '%'. Later,
|
Add a new defined command. The Name must star with '%'. Later,
|
||||||
if 'Name X' is used, it is replaced by Anything where #1 is replaced
|
if 'Name X' is used, it is replaced by Anything where #1 is replaced
|
||||||
by X. Currently at most one argument is possible. To see
|
by X.
|
||||||
definitions in scope, use help -defs.
|
Restrictions: Currently at most one argument is possible, and a defined
|
||||||
|
command cannot appear in a pipe.
|
||||||
|
To see what definitions are in scope, use help -defs.
|
||||||
examples:
|
examples:
|
||||||
dc %tnp p -cat=NP -lang=Eng #1 | l -lang=Swe -- translate NPs
|
dc %tnp p -cat=NP -lang=Eng #1 | l -lang=Swe -- translate NPs
|
||||||
%tnp "this man" | p -lang=Swe -- translate and parse
|
%tnp "this man" -- translate and parse
|
||||||
|
|
||||||
dt, define_term Name Tree
|
dt, define_term Name Tree
|
||||||
Add a constant for a tree. The constant can later be called by
|
Add a constant for a tree. The constant can later be called by
|
||||||
prefixing it with '$'. It is not yet usable as a subterm. To see
|
prefixing it with '$'.
|
||||||
definitions in scope, use help -defs.
|
Restriction: These terms are not yet usable as a subterm.
|
||||||
|
To see what definitions are in scope, use help -defs.
|
||||||
examples:
|
examples:
|
||||||
p -cat=NP "this man" | dt tm -- define tm as parse result
|
p -cat=NP "this man" | dt tm -- define tm as parse result
|
||||||
l -all $tm -- linearize tm in all forms
|
l -all $tm -- linearize tm in all forms
|
||||||
@@ -447,6 +450,12 @@ q, quit: q
|
|||||||
example:
|
example:
|
||||||
! ls
|
! ls
|
||||||
|
|
||||||
|
?, system_command: ? String
|
||||||
|
Issues a system command that receives its arguments from GF pipe
|
||||||
|
and returns a value to GF.
|
||||||
|
example:
|
||||||
|
h | ? 'wc -l' | p -cat=Num
|
||||||
|
|
||||||
|
|
||||||
-- Flags. The availability of flags is defined separately for each command.
|
-- Flags. The availability of flags is defined separately for each command.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user