mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-15 06:02:55 -06:00
ModuleName and Ident are now distinct types
This makes the documentation clearer, and can potentially catch more programming mistakes.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user