From 0f444d889302b68f2b7edbe31e4ddcd37e45454a Mon Sep 17 00:00:00 2001 From: aarne Date: Tue, 7 Dec 2010 19:28:40 +0000 Subject: [PATCH] optimize-pgf and file flag in pg -pgf --- src/compiler/GF/Command/Commands.hs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/compiler/GF/Command/Commands.hs b/src/compiler/GF/Command/Commands.hs index 530dc236f..47960f0fe 100644 --- a/src/compiler/GF/Command/Commands.hs +++ b/src/compiler/GF/Command/Commands.hs @@ -23,6 +23,7 @@ import PGF.Printer import PGF.Probabilistic -- (getProbsFromFile,prProbabilities,defaultProbabilities) import PGF.Generate (generateRandomFrom) ---- import PGF.Tree (Tree(Fun), expr2tree, tree2expr) +import PGF.Optimize import GF.Compile.Export import GF.Compile.ToAPI import GF.Compile.ExampleBased @@ -34,12 +35,12 @@ import GF.Command.Messages import GF.Text.Lexing import GF.Text.Transliterations import GF.Quiz -import GFC (writePGF) import GF.Command.TreeOperations ---- temporary place for typecheck and compute import GF.Data.Operations +import Data.Binary (encodeFile) import Data.List import Data.Maybe import qualified Data.Map as Map @@ -548,6 +549,7 @@ allCommands env@(pgf, mos) = Map.fromList [ exec = \opts _ -> prGrammar opts, flags = [ --"cat", + ("file", "set the file name when printing with -pgf option"), ("lang", "select languages for the some options (default all languages)"), ("printer","select the printing format (see gfc --help)") ], @@ -556,6 +558,7 @@ allCommands env@(pgf, mos) = Map.fromList [ ("fullform", "print the fullform lexicon"), ("funs", "show just the names and types of abstract syntax functions"), ("missing","show just the names of functions that have no linearization"), + ("opt", "optimize the generated pgf"), ("pgf", "write current pgf image in file"), ("words", "print the list of words") ], @@ -1077,7 +1080,12 @@ allCommands env@(pgf, mos) = Map.fromList [ _ -> fromExprs es prGrammar opts - | isOpt "pgf" opts = dieIOE (writePGF noOptions pgf) >> return void ---- opts + | isOpt "pgf" opts = do + let pgf1 = if isOpt "opt" opts then optimizePGF pgf else pgf + let outfile = valStrOpts "file" (showCId (abstractName pgf) ++ ".pgf") opts + encodeFile outfile pgf1 + putStrLn $ "wrote file " ++ outfile + return void | isOpt "cats" opts = return $ fromString $ unwords $ map showCId $ categories pgf | isOpt "funs" opts = return $ fromString $ unlines $ map showFun $ funsigs pgf | isOpt "fullform" opts = return $ fromString $ concatMap (morpho "" prFullFormLexicon) $ optLangs opts