forked from GitHub/gf-core
"Committed_by_peb"
This commit is contained in:
@@ -5,9 +5,9 @@
|
|||||||
-- Stability : (stable)
|
-- Stability : (stable)
|
||||||
-- Portability : (portable)
|
-- Portability : (portable)
|
||||||
--
|
--
|
||||||
-- > CVS $Date: 2005/05/12 10:03:33 $
|
-- > CVS $Date: 2005/05/17 11:20:25 $
|
||||||
-- > CVS $Author: aarne $
|
-- > CVS $Author: peb $
|
||||||
-- > CVS $Revision: 1.35 $
|
-- > CVS $Revision: 1.36 $
|
||||||
--
|
--
|
||||||
-- Application Programmer's Interface to GF; also used by Shell. AR 10/11/2001
|
-- 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
|
optPrintGrammar opts = customOrDefault opts grammarPrinter customGrammarPrinter
|
||||||
|
|
||||||
optPrintMultiGrammar :: Options -> CanonGrammar -> String
|
optPrintMultiGrammar :: Options -> CanonGrammar -> String
|
||||||
optPrintMultiGrammar opts = encodeId . pmg . encode
|
optPrintMultiGrammar opts = encodeId . pmg opts . encode
|
||||||
where
|
where
|
||||||
pmg = customOrDefault opts grammarPrinter customMultiGrammarPrinter
|
pmg = customOrDefault opts grammarPrinter customMultiGrammarPrinter
|
||||||
-- if -utf8 was given, convert from language specific codings
|
-- if -utf8 was given, convert from language specific codings
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
-- Stability : (stable)
|
-- Stability : (stable)
|
||||||
-- Portability : (portable)
|
-- Portability : (portable)
|
||||||
--
|
--
|
||||||
-- > CVS $Date: 2005/05/13 12:40:18 $
|
-- > CVS $Date: 2005/05/17 11:20:25 $
|
||||||
-- > CVS $Author: peb $
|
-- > CVS $Author: peb $
|
||||||
-- > CVS $Revision: 1.18 $
|
-- > CVS $Revision: 1.19 $
|
||||||
--
|
--
|
||||||
-- Handles printing a CFGrammar in CFGM format.
|
-- Handles printing a CFGrammar in CFGM format.
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
@@ -32,32 +32,37 @@ import GF.Data.ErrM
|
|||||||
import qualified GF.Infra.Option as Option
|
import qualified GF.Infra.Option as Option
|
||||||
|
|
||||||
import Data.List (intersperse)
|
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,
|
-- | FIXME: should add an Options argument,
|
||||||
-- to be able to decide which CFG conversion one wants to use
|
-- to be able to decide which CFG conversion one wants to use
|
||||||
prCanonAsCFGM :: CanonGrammar -> String
|
prCanonAsCFGM :: Option.Options -> CanonGrammar -> String
|
||||||
prCanonAsCFGM gr = unlines $ map (uncurry (prLangAsCFGM gr)) xs
|
prCanonAsCFGM opts gr = unlines $ map (prLangAsCFGM gr) xs
|
||||||
where
|
where
|
||||||
cncs = maybe [] (allConcretes gr) (greatestAbstract gr)
|
cncs = maybe [] (allConcretes gr) (greatestAbstract gr)
|
||||||
cncms = map (\i -> (i,fromOk (lookupModule gr i))) cncs
|
cncms = map (\i -> (i,fromOk (lookupModule gr i))) cncs
|
||||||
fromOk (Ok x) = x
|
fromOk (Ok x) = x
|
||||||
fromOk (Bad y) = error y
|
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
|
-- | FIXME: need to look in abstract module too
|
||||||
getFlag :: [Flag] -> String -> Maybe String
|
getFlag :: [Flag] -> String -> Maybe String
|
||||||
getFlag fs x = listToMaybe [v | Flg (IC k) (IC v) <- fs, k == x]
|
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)
|
-- instead of 'Cnv.gfc2cfg' (which recalculates the grammar every time)
|
||||||
--
|
--
|
||||||
-- FIXME: (2) Should use the state options, when calculating the CFG
|
-- FIXME: (2) Should use the state options, when calculating the CFG
|
||||||
-- (this is solved automatically if one solves (1) above)
|
-- (this is solved automatically if one solves (1) above)
|
||||||
prLangAsCFGM :: CanonGrammar -> Ident -> Maybe String -> String
|
prLangAsCFGM :: CanonGrammar -> (Ident, Maybe String, Maybe String) -> String
|
||||||
prLangAsCFGM gr i start = prCFGrammarAsCFGM (Cnv.gfc2cfg opts (gr, i)) i start
|
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
|
-- 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 :: GT.CGrammar -> Ident -> Maybe String -> String
|
||||||
prCFGrammarAsCFGM gr i start = PrintCFG.printTree $ cfGrammarToCFGM gr i start
|
prCFGrammarAsCFGM gr i start = PrintCFG.printTree $ cfGrammarToCFGM gr i start
|
||||||
|
|||||||
@@ -4,9 +4,9 @@
|
|||||||
-- Stability : (stable)
|
-- Stability : (stable)
|
||||||
-- Portability : (portable)
|
-- Portability : (portable)
|
||||||
--
|
--
|
||||||
-- > CVS $Date: 2005/05/13 12:40:19 $
|
-- > CVS $Date: 2005/05/17 11:20:25 $
|
||||||
-- > CVS $Author: peb $
|
-- > CVS $Author: peb $
|
||||||
-- > CVS $Revision: 1.9 $
|
-- > CVS $Revision: 1.10 $
|
||||||
--
|
--
|
||||||
-- All conversions from GFC
|
-- All conversions from GFC
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
@@ -34,11 +34,13 @@ import qualified GF.Conversion.MCFGtoCFG as M2C
|
|||||||
|
|
||||||
import GF.Infra.Print
|
import GF.Infra.Print
|
||||||
|
|
||||||
|
import GF.System.Tracing
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
-- * GFC -> MCFG & CFG, using options to decide which conversion is used
|
-- * GFC -> MCFG & CFG, using options to decide which conversion is used
|
||||||
|
|
||||||
gfc2mcfg2cfg :: Options -> (CanonGrammar, Ident) -> (MGrammar, CGrammar)
|
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
|
where e2c = mcfg2cfg
|
||||||
e2m = case getOptVal opts firstCat of
|
e2m = case getOptVal opts firstCat of
|
||||||
Just cat -> flip removeErasing [identC cat]
|
Just cat -> flip removeErasing [identC cat]
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
-- Stability : (stable)
|
-- Stability : (stable)
|
||||||
-- Portability : (portable)
|
-- Portability : (portable)
|
||||||
--
|
--
|
||||||
-- > CVS $Date: 2005/05/12 10:03:33 $
|
-- > CVS $Date: 2005/05/17 11:20:25 $
|
||||||
-- > CVS $Author: aarne $
|
-- > CVS $Author: peb $
|
||||||
-- > CVS $Revision: 1.36 $
|
-- > CVS $Revision: 1.37 $
|
||||||
--
|
--
|
||||||
-- GF shell command interpreter.
|
-- 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'
|
returnArg (AString (optPrintMultiGrammar opts cgr)) sa'
|
||||||
CShowGrammarGraph -> do
|
CShowGrammarGraph -> do
|
||||||
---- sa' <- changeState purgeShellState sa
|
---- 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"
|
g1 = system "dot -Tps grphtmp.dot >grphtmp.ps"
|
||||||
g2 = system "gv grphtmp.ps &"
|
g2 = system "gv grphtmp.ps &"
|
||||||
g3 = return () ---- system "rm -f grphtmp.*"
|
g3 = return () ---- system "rm -f grphtmp.*"
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
-- Stability : (stable)
|
-- Stability : (stable)
|
||||||
-- Portability : (portable)
|
-- Portability : (portable)
|
||||||
--
|
--
|
||||||
-- > CVS $Date: 2005/05/13 12:40:20 $
|
-- > CVS $Date: 2005/05/17 11:20:25 $
|
||||||
-- > CVS $Author: peb $
|
-- > CVS $Author: peb $
|
||||||
-- > CVS $Revision: 1.62 $
|
-- > CVS $Revision: 1.63 $
|
||||||
--
|
--
|
||||||
-- A database for customizable GF shell commands.
|
-- A database for customizable GF shell commands.
|
||||||
--
|
--
|
||||||
@@ -128,7 +128,7 @@ customGrammarParser :: CustomData (FilePath -> IOE C.CanonGrammar)
|
|||||||
customGrammarPrinter :: CustomData (StateGrammar -> String)
|
customGrammarPrinter :: CustomData (StateGrammar -> String)
|
||||||
|
|
||||||
-- | multiGrammarPrinter, \"-printer=x\"
|
-- | multiGrammarPrinter, \"-printer=x\"
|
||||||
customMultiGrammarPrinter :: CustomData (CanonGrammar -> String)
|
customMultiGrammarPrinter :: CustomData (Options -> CanonGrammar -> String)
|
||||||
|
|
||||||
-- | syntaxPrinter, \"-printer=x\"
|
-- | syntaxPrinter, \"-printer=x\"
|
||||||
customSyntaxPrinter :: CustomData (GF.Grammar -> String)
|
customSyntaxPrinter :: CustomData (GF.Grammar -> String)
|
||||||
@@ -277,8 +277,8 @@ customGrammarPrinter =
|
|||||||
customMultiGrammarPrinter =
|
customMultiGrammarPrinter =
|
||||||
customData "Printers for multiple grammars, selected by option -printer=x" $
|
customData "Printers for multiple grammars, selected by option -printer=x" $
|
||||||
[
|
[
|
||||||
(strCI "gfcm", MC.prCanon)
|
(strCI "gfcm", const MC.prCanon)
|
||||||
,(strCI "header", MC.prCanonMGr)
|
,(strCI "header", const MC.prCanonMGr)
|
||||||
,(strCI "cfgm", prCanonAsCFGM)
|
,(strCI "cfgm", prCanonAsCFGM)
|
||||||
,(strCI "graph", visualizeCanonGrammar)
|
,(strCI "graph", visualizeCanonGrammar)
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
-- Stability : (stable)
|
-- Stability : (stable)
|
||||||
-- Portability : (portable)
|
-- Portability : (portable)
|
||||||
--
|
--
|
||||||
-- > CVS $Date: 2005/04/21 16:23:54 $
|
-- > CVS $Date: 2005/05/17 11:20:26 $
|
||||||
-- > CVS $Author: bringert $
|
-- > CVS $Author: peb $
|
||||||
-- > CVS $Revision: 1.8 $
|
-- > CVS $Revision: 1.9 $
|
||||||
--
|
--
|
||||||
-- Print a graph of module dependencies in Graphviz DOT format
|
-- 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 qualified GF.Infra.Modules as M
|
||||||
import GF.Canon.GFC
|
import GF.Canon.GFC
|
||||||
import GF.Infra.Ident
|
import GF.Infra.Ident
|
||||||
|
import GF.Infra.Option
|
||||||
import GF.Grammar.Grammar (SourceGrammar)
|
import GF.Grammar.Grammar (SourceGrammar)
|
||||||
|
|
||||||
import Data.List (intersperse, nub)
|
import Data.List (intersperse, nub)
|
||||||
@@ -42,8 +43,8 @@ data Node = Node {
|
|||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
|
|
||||||
visualizeCanonGrammar :: CanonGrammar -> String
|
visualizeCanonGrammar :: Options -> CanonGrammar -> String
|
||||||
visualizeCanonGrammar = prGraph . canon2graph
|
visualizeCanonGrammar opts = prGraph . canon2graph
|
||||||
|
|
||||||
visualizeSourceGrammar :: SourceGrammar -> String
|
visualizeSourceGrammar :: SourceGrammar -> String
|
||||||
visualizeSourceGrammar = prGraph . source2graph
|
visualizeSourceGrammar = prGraph . source2graph
|
||||||
|
|||||||
Reference in New Issue
Block a user