implement rf in the C shell

This commit is contained in:
Krasimir Angelov
2017-08-30 19:19:10 +02:00
parent 34294bf36e
commit 13a854d349

View File

@@ -40,7 +40,7 @@ import Data.Maybe
import qualified Data.Map as Map import qualified Data.Map as Map
--import System.Cmd(system) -- use GF.Infra.UseIO.restricedSystem instead! --import System.Cmd(system) -- use GF.Infra.UseIO.restricedSystem instead!
--import GF.System.Process --import GF.System.Process
--import GF.Text.Pretty import GF.Text.Pretty
--import Data.List (sort) --import Data.List (sort)
import Control.Monad(mplus) import Control.Monad(mplus)
--import Debug.Trace --import Debug.Trace
@@ -377,7 +377,6 @@ pgfCommands = Map.fromList [
flags = [("number","take at most this many trees")] ++ treeOpFlags undefined{-pgf-} flags = [("number","take at most this many trees")] ++ treeOpFlags undefined{-pgf-}
}), }),
-} -}
{-
("rf", emptyCommandInfo { ("rf", emptyCommandInfo {
longname = "read_file", longname = "read_file",
synopsis = "read string or tree input from a file", synopsis = "read string or tree input from a file",
@@ -392,21 +391,21 @@ pgfCommands = Map.fromList [
("lines","return the list of lines, instead of the singleton of all contents"), ("lines","return the list of lines, instead of the singleton of all contents"),
("tree","convert strings into trees") ("tree","convert strings into trees")
], ],
exec = \env@(pgf, mos) opts _ -> do exec = needPGF $ \opts _ env@(pgf, mos) -> do
let file = valStrOpts "file" "_gftmp" opts let file = valStrOpts "file" "_gftmp" opts
let exprs [] = ([],empty) let exprs [] = ([],empty)
exprs ((n,s):ls) | null s exprs ((n,s):ls) | null s
= exprs ls = exprs ls
exprs ((n,s):ls) = case H.readExpr s of exprs ((n,s):ls) = case readExpr s of
Just e -> let (es,err) = exprs ls Just e -> let (es,err) = exprs ls
in case H.inferExpr pgf e of in case inferExpr pgf e of
Right (e,t) -> (e:es,err) Right (e,t) -> (e:es,err)
Left tcerr -> (es,"on line" <+> n <> ':' $$ nest 2 (H.ppTcError tcerr) $$ err) Left msg -> (es,"on line" <+> n <> ':' $$ msg $$ err)
Nothing -> let (es,err) = exprs ls Nothing -> let (es,err) = exprs ls
in (es,"on line" <+> n <> ':' <+> "parse error" $$ err) in (es,"on line" <+> n <> ':' <+> "parse error" $$ err)
returnFromLines ls = case exprs ls of returnFromLines ls = case exprs ls of
(es, err) | null es -> return $ pipeMessage $ render (err $$ "no trees found") (es, err) | null es -> return $ pipeMessage $ render (err $$ "no trees found")
| otherwise -> return $ pipeWithMessage es (render err) | otherwise -> return $ pipeWithMessage (map hsExpr es) (render err)
s <- restricted $ readFile file s <- restricted $ readFile file
case opts of case opts of
@@ -418,7 +417,7 @@ pgfCommands = Map.fromList [
_ -> return (fromString s), _ -> return (fromString s),
flags = [("file","the input file name")] flags = [("file","the input file name")]
}), }),
{-
("rt", emptyCommandInfo { ("rt", emptyCommandInfo {
longname = "rank_trees", longname = "rank_trees",
synopsis = "show trees in an order of decreasing probability", synopsis = "show trees in an order of decreasing probability",