diff options
| author | hallgren <hallgren@chalmers.se> | 2014-10-21 19:20:31 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2014-10-21 19:20:31 +0000 |
| commit | 391b301881bee7de9580f2c6d819144161e6a51d (patch) | |
| tree | 11e61e5252bfe6939eee9ef14d19bd7ca6c8bb40 /src/compiler/GF/Infra | |
| parent | 3bfcfa157dc291e03bfb4db3baed8b0098d76f50 (diff) | |
ModuleName and Ident are now distinct types
This makes the documentation clearer, and can potentially catch more
programming mistakes.
Diffstat (limited to 'src/compiler/GF/Infra')
| -rw-r--r-- | src/compiler/GF/Infra/Dependencies.hs | 35 | ||||
| -rw-r--r-- | src/compiler/GF/Infra/Ident.hs | 10 |
2 files changed, 28 insertions, 17 deletions
diff --git a/src/compiler/GF/Infra/Dependencies.hs b/src/compiler/GF/Infra/Dependencies.hs index 8c3d6666f..91ca0ad14 100644 --- a/src/compiler/GF/Infra/Dependencies.hs +++ b/src/compiler/GF/Infra/Dependencies.hs @@ -3,15 +3,16 @@ module GF.Infra.Dependencies ( ) where import GF.Grammar.Grammar -import GF.Infra.Ident(Ident,showIdent) +--import GF.Infra.Ident(Ident) +import GF.Text.Pretty(render) import Data.List (nub,isPrefixOf) -- the list gives the only modules to show, e.g. to hide the library details -depGraph :: Maybe [String] -> SourceGrammar -> String +depGraph :: Maybe [String] -> Grammar -> String depGraph only = prDepGraph . grammar2moddeps only -prDepGraph :: [(Ident,ModDeps)] -> String +prDepGraph :: [(ModuleName,ModDeps)] -> String prDepGraph deps = unlines $ [ "digraph {" ] ++ @@ -20,16 +21,16 @@ prDepGraph deps = unlines $ [ "}" ] where - mkNode (i,dep) = unwords [showIdent i, "[",nodeAttr (modtype dep),"]"] + mkNode (i,dep) = unwords [render i, "[",nodeAttr (modtype dep),"]"] nodeAttr ty = case ty of MTAbstract -> "style = \"solid\", shape = \"box\"" MTConcrete _ -> "style = \"solid\", shape = \"ellipse\"" _ -> "style = \"dashed\", shape = \"ellipse\"" mkArrows (i,dep) = - [unwords [showIdent i,"->",showIdent j,"[",arrowAttr "of","]"] | j <- ofs dep] ++ - [unwords [showIdent i,"->",showIdent j,"[",arrowAttr "ex","]"] | j <- extendeds dep] ++ - [unwords [showIdent i,"->",showIdent j,"[",arrowAttr "op","]"] | j <- openeds dep] ++ - [unwords [showIdent i,"->",showIdent j,"[",arrowAttr "ed","]"] | j <- extrads dep] + [unwords [render i,"->",render j,"[",arrowAttr "of","]"] | j <- ofs dep] ++ + [unwords [render i,"->",render j,"[",arrowAttr "ex","]"] | j <- extendeds dep] ++ + [unwords [render i,"->",render j,"[",arrowAttr "op","]"] | j <- openeds dep] ++ + [unwords [render i,"->",render j,"[",arrowAttr "ed","]"] | j <- extrads dep] arrowAttr s = case s of "of" -> "style = \"solid\", arrowhead = \"empty\"" "ex" -> "style = \"solid\"" @@ -38,18 +39,18 @@ prDepGraph deps = unlines $ [ data ModDeps = ModDeps { modtype :: ModuleType, - ofs :: [Ident], - extendeds :: [Ident], - openeds :: [Ident], - extrads :: [Ident], - functors :: [Ident], - interfaces :: [Ident], - instances :: [Ident] + ofs :: [ModuleName], + extendeds :: [ModuleName], + openeds :: [ModuleName], + extrads :: [ModuleName], + functors :: [ModuleName], + interfaces :: [ModuleName], + instances :: [ModuleName] } noModDeps = ModDeps MTAbstract [] [] [] [] [] [] [] -grammar2moddeps :: Maybe [String] -> SourceGrammar -> [(Ident,ModDeps)] +grammar2moddeps :: Maybe [String] -> Grammar -> [(ModuleName,ModDeps)] grammar2moddeps monly gr = [(i,depMod i m) | (i,m) <- modules gr, yes i] where depMod i m = @@ -64,7 +65,7 @@ grammar2moddeps monly gr = [(i,depMod i m) | (i,m) <- modules gr, yes i] extrads = nub $ filter yes $ mexdeps m } yes i = case monly of - Just only -> match (showIdent i) only + Just only -> match (render i) only _ -> True match s os = any (\x -> doMatch x s) os doMatch x s = case last x of diff --git a/src/compiler/GF/Infra/Ident.hs b/src/compiler/GF/Infra/Ident.hs index 71e86fb37..7d0bed804 100644 --- a/src/compiler/GF/Infra/Ident.hs +++ b/src/compiler/GF/Infra/Ident.hs @@ -13,6 +13,7 @@ ----------------------------------------------------------------------------- module GF.Infra.Ident (-- ** Identifiers + ModuleName(..), moduleNameS, Ident, ident2utf8, showIdent, prefixIdent, identS, identC, identV, identA, identAV, identW, argIdent, isArgIdent, getArgIndex, @@ -34,6 +35,15 @@ import PGF.Internal(Binary(..)) import GF.Text.Pretty +-- | Module names +newtype ModuleName = MN Ident deriving (Eq,Ord) + +moduleNameS = MN . identS + +instance Show ModuleName where showsPrec d (MN m) = showsPrec d m +instance Pretty ModuleName where pp (MN m) = pp m + + -- | the constructors labelled /INTERNAL/ are -- internal representation never returned by the parser data Ident = |
