From 197c3029e36364299e5632579c00b9daae7fa21a Mon Sep 17 00:00:00 2001 From: peb Date: Tue, 17 May 2005 10:20:25 +0000 Subject: [PATCH] "Committed_by_peb" --- src/GF/API.hs | 8 ++++---- src/GF/CFGM/PrintCFGrammar.hs | 25 ++++++++++++++---------- src/GF/Conversion/GFC.hs | 8 +++++--- src/GF/Shell.hs | 8 ++++---- src/GF/UseGrammar/Custom.hs | 10 +++++----- src/GF/Visualization/VisualizeGrammar.hs | 11 ++++++----- 6 files changed, 39 insertions(+), 31 deletions(-) diff --git a/src/GF/API.hs b/src/GF/API.hs index 8d3b31475..20f32b59e 100644 --- a/src/GF/API.hs +++ b/src/GF/API.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/05/12 10:03:33 $ --- > CVS $Author: aarne $ --- > CVS $Revision: 1.35 $ +-- > CVS $Date: 2005/05/17 11:20:25 $ +-- > CVS $Author: peb $ +-- > CVS $Revision: 1.36 $ -- -- Application Programmer's Interface to GF; also used by Shell. AR 10/11/2001 ----------------------------------------------------------------------------- @@ -305,7 +305,7 @@ optPrintGrammar :: Options -> StateGrammar -> String optPrintGrammar opts = customOrDefault opts grammarPrinter customGrammarPrinter optPrintMultiGrammar :: Options -> CanonGrammar -> String -optPrintMultiGrammar opts = encodeId . pmg . encode +optPrintMultiGrammar opts = encodeId . pmg opts . encode where pmg = customOrDefault opts grammarPrinter customMultiGrammarPrinter -- if -utf8 was given, convert from language specific codings diff --git a/src/GF/CFGM/PrintCFGrammar.hs b/src/GF/CFGM/PrintCFGrammar.hs index bf7d8320a..bea35ad35 100644 --- a/src/GF/CFGM/PrintCFGrammar.hs +++ b/src/GF/CFGM/PrintCFGrammar.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/05/13 12:40:18 $ +-- > CVS $Date: 2005/05/17 11:20:25 $ -- > CVS $Author: peb $ --- > CVS $Revision: 1.18 $ +-- > CVS $Revision: 1.19 $ -- -- Handles printing a CFGrammar in CFGM format. ----------------------------------------------------------------------------- @@ -32,32 +32,37 @@ import GF.Data.ErrM import qualified GF.Infra.Option as Option import Data.List (intersperse) -import Data.Maybe (listToMaybe, maybe) +import Data.Maybe (listToMaybe, maybeToList, maybe) + +import GF.Infra.Print +import GF.System.Tracing -- | FIXME: should add an Options argument, -- to be able to decide which CFG conversion one wants to use -prCanonAsCFGM :: CanonGrammar -> String -prCanonAsCFGM gr = unlines $ map (uncurry (prLangAsCFGM gr)) xs +prCanonAsCFGM :: Option.Options -> CanonGrammar -> String +prCanonAsCFGM opts gr = unlines $ map (prLangAsCFGM gr) xs where cncs = maybe [] (allConcretes gr) (greatestAbstract gr) cncms = map (\i -> (i,fromOk (lookupModule gr i))) cncs fromOk (Ok x) = x fromOk (Bad y) = error y - xs = [(i,getFlag fs "startcat") | (i,ModMod (Module{flags=fs})) <- cncms] + xs = tracePrt "CFGM languages" (prtBefore "\n") + [ (i, getFlag fs "startcat", getFlag fs "conversion") | + (i, ModMod (Module{flags=fs})) <- cncms ] -- | FIXME: need to look in abstract module too getFlag :: [Flag] -> String -> Maybe String getFlag fs x = listToMaybe [v | Flg (IC k) (IC v) <- fs, k == x] --- | FIXME: (1) Should use 'ShellState.stateCFG' +-- FIXME: (1) Should use 'ShellState.stateCFG' -- instead of 'Cnv.gfc2cfg' (which recalculates the grammar every time) -- -- FIXME: (2) Should use the state options, when calculating the CFG -- (this is solved automatically if one solves (1) above) -prLangAsCFGM :: CanonGrammar -> Ident -> Maybe String -> String -prLangAsCFGM gr i start = prCFGrammarAsCFGM (Cnv.gfc2cfg opts (gr, i)) i start +prLangAsCFGM :: CanonGrammar -> (Ident, Maybe String, Maybe String) -> String +prLangAsCFGM gr (i, start, cnv) = prCFGrammarAsCFGM (Cnv.gfc2cfg opts (gr, i)) i start -- prLangAsCFGM gr i start = prCFGrammarAsCFGM (Cnv.cfg (Cnv.pInfo opts gr i)) i start - where opts = Option.Opts [Option.gfcConversion "nondet"] + where opts = Option.Opts $ maybeToList $ fmap Option.gfcConversion cnv prCFGrammarAsCFGM :: GT.CGrammar -> Ident -> Maybe String -> String prCFGrammarAsCFGM gr i start = PrintCFG.printTree $ cfGrammarToCFGM gr i start diff --git a/src/GF/Conversion/GFC.hs b/src/GF/Conversion/GFC.hs index d0b3ea9d3..a2c2c9c91 100644 --- a/src/GF/Conversion/GFC.hs +++ b/src/GF/Conversion/GFC.hs @@ -4,9 +4,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/05/13 12:40:19 $ +-- > CVS $Date: 2005/05/17 11:20:25 $ -- > CVS $Author: peb $ --- > CVS $Revision: 1.9 $ +-- > CVS $Revision: 1.10 $ -- -- All conversions from GFC ----------------------------------------------------------------------------- @@ -34,11 +34,13 @@ import qualified GF.Conversion.MCFGtoCFG as M2C import GF.Infra.Print +import GF.System.Tracing + ---------------------------------------------------------------------- -- * GFC -> MCFG & CFG, using options to decide which conversion is used gfc2mcfg2cfg :: Options -> (CanonGrammar, Ident) -> (MGrammar, CGrammar) -gfc2mcfg2cfg opts = \g -> let e = g2e g in (e2m e, e2c e) +gfc2mcfg2cfg opts = \g -> let e = g2e g in trace2 "Options" (show opts) (e2m e, e2c e) where e2c = mcfg2cfg e2m = case getOptVal opts firstCat of Just cat -> flip removeErasing [identC cat] diff --git a/src/GF/Shell.hs b/src/GF/Shell.hs index 1c0e63f22..7dca7b066 100644 --- a/src/GF/Shell.hs +++ b/src/GF/Shell.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/05/12 10:03:33 $ --- > CVS $Author: aarne $ --- > CVS $Revision: 1.36 $ +-- > CVS $Date: 2005/05/17 11:20:25 $ +-- > CVS $Author: peb $ +-- > CVS $Revision: 1.37 $ -- -- GF shell command interpreter. ----------------------------------------------------------------------------- @@ -272,7 +272,7 @@ execC co@(comm, opts0) sa@((st,(h,_)),a) = checkOptions st co >> case comm of returnArg (AString (optPrintMultiGrammar opts cgr)) sa' CShowGrammarGraph -> do ---- sa' <- changeState purgeShellState sa - let g0 = writeFile "grphtmp.dot" $ visualizeCanonGrammar cgr + let g0 = writeFile "grphtmp.dot" $ visualizeCanonGrammar opts cgr g1 = system "dot -Tps grphtmp.dot >grphtmp.ps" g2 = system "gv grphtmp.ps &" g3 = return () ---- system "rm -f grphtmp.*" diff --git a/src/GF/UseGrammar/Custom.hs b/src/GF/UseGrammar/Custom.hs index 65657ca26..08136fad8 100644 --- a/src/GF/UseGrammar/Custom.hs +++ b/src/GF/UseGrammar/Custom.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/05/13 12:40:20 $ +-- > CVS $Date: 2005/05/17 11:20:25 $ -- > CVS $Author: peb $ --- > CVS $Revision: 1.62 $ +-- > CVS $Revision: 1.63 $ -- -- A database for customizable GF shell commands. -- @@ -128,7 +128,7 @@ customGrammarParser :: CustomData (FilePath -> IOE C.CanonGrammar) customGrammarPrinter :: CustomData (StateGrammar -> String) -- | multiGrammarPrinter, \"-printer=x\" -customMultiGrammarPrinter :: CustomData (CanonGrammar -> String) +customMultiGrammarPrinter :: CustomData (Options -> CanonGrammar -> String) -- | syntaxPrinter, \"-printer=x\" customSyntaxPrinter :: CustomData (GF.Grammar -> String) @@ -277,8 +277,8 @@ customGrammarPrinter = customMultiGrammarPrinter = customData "Printers for multiple grammars, selected by option -printer=x" $ [ - (strCI "gfcm", MC.prCanon) - ,(strCI "header", MC.prCanonMGr) + (strCI "gfcm", const MC.prCanon) + ,(strCI "header", const MC.prCanonMGr) ,(strCI "cfgm", prCanonAsCFGM) ,(strCI "graph", visualizeCanonGrammar) ] diff --git a/src/GF/Visualization/VisualizeGrammar.hs b/src/GF/Visualization/VisualizeGrammar.hs index 1c3d0589a..e217dd7e2 100644 --- a/src/GF/Visualization/VisualizeGrammar.hs +++ b/src/GF/Visualization/VisualizeGrammar.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/04/21 16:23:54 $ --- > CVS $Author: bringert $ --- > CVS $Revision: 1.8 $ +-- > CVS $Date: 2005/05/17 11:20:26 $ +-- > CVS $Author: peb $ +-- > CVS $Revision: 1.9 $ -- -- Print a graph of module dependencies in Graphviz DOT format ----------------------------------------------------------------------------- @@ -19,6 +19,7 @@ module GF.Visualization.VisualizeGrammar ( visualizeCanonGrammar, import qualified GF.Infra.Modules as M import GF.Canon.GFC import GF.Infra.Ident +import GF.Infra.Option import GF.Grammar.Grammar (SourceGrammar) import Data.List (intersperse, nub) @@ -42,8 +43,8 @@ data Node = Node { deriving Show -visualizeCanonGrammar :: CanonGrammar -> String -visualizeCanonGrammar = prGraph . canon2graph +visualizeCanonGrammar :: Options -> CanonGrammar -> String +visualizeCanonGrammar opts = prGraph . canon2graph visualizeSourceGrammar :: SourceGrammar -> String visualizeSourceGrammar = prGraph . source2graph