graphmod 1.2.4 → 1.2.5
raw patch · 3 files changed
+42/−10 lines, 3 files
Files
- graphmod.cabal +2/−2
- src/Main.hs +15/−5
- src/Utils.hs +25/−3
graphmod.cabal view
@@ -1,10 +1,10 @@ name: graphmod-version: 1.2.4+version: 1.2.5 license: BSD3 license-file: LICENSE author: Iavor S. Diatchki maintainer: iavor.diatchki@gmail.com-homepage: http://github.com/yav/graphmod+homepage: http://github.com/yav/graphmod/wiki build-type: Simple cabal-version: >= 1.2 synopsis: Present the module dependencies of a program as a "dot" graph.
src/Main.hs view
@@ -28,7 +28,7 @@ | otherwise -> do g <- graph (add_current opts) (map to_input ms)- putStrLn (make_dot (color_scheme opts)+ putStrLn (make_dot (graph_size opts) (color_scheme opts) (use_clusters opts) g) where opts = foldr ($) default_opts fs @@ -204,10 +204,12 @@ -- Render edges and a trie into the dot language ---------------------------------------------------------------------------------make_dot :: Int -> Bool -> (Edges,NodesC) -> String-make_dot col cl (es,t) =+make_dot :: String -> Int -> Bool -> (Edges,NodesC) -> String+make_dot sz col cl (es,t) = showDot $- do if cl then make_clustered_dot (colors col) t+ do attribute ("size", sz)+ attribute ("ratio", "fill")+ if cl then make_clustered_dot (colors col) t else make_unclustered_dot (colors col) "" t >> return () forM_ (IMap.toList es) $ \(x,ys) -> forM_ (Set.toList ys) $ \y -> userNodeId x .->. userNodeId y@@ -323,6 +325,7 @@ , show_version :: Bool , color_scheme :: Int , prune_edges :: Bool+ , graph_size :: String } type IgnoreSet = Trie.Trie String IgnoreSpec@@ -341,6 +344,7 @@ , show_version = False , color_scheme = 0 , prune_edges = False+ , graph_size = "6,4" } options :: [OptDescr OptT]@@ -370,8 +374,11 @@ "Display modules NAME and NAME.* as one node" , Option ['p'] ["prune-edges"] (NoArg set_prune)- "Prune edges."+ "Remove imports if the module is imported by another imported module" + , Option ['d'] ["graph-dim"] (ReqArg set_size "SIZE,SIZE")+ "Set dimensions of the graph. See the `size` attribute of graphvize."+ , Option ['s'] ["colors"] (ReqArg add_color_scheme "NUM") "Choose a color scheme number (0-5)" @@ -430,3 +437,6 @@ set_prune :: OptT set_prune o = o { prune_edges = True }++set_size :: String -> OptT+set_size s o = o { graph_size = s }
src/Utils.hs view
@@ -11,7 +11,7 @@ , suffixes ) where -import Language.Haskell.Lexer(lexerPass1,Token(..),PosToken)+import Language.Haskell.Lexer(lexerPass1,Token(..),PosToken,line) import Data.Maybe(catMaybes) import Data.List(intersperse,isPrefixOf)@@ -25,8 +25,30 @@ -- | Get the imports from a string that represents a program. parseString :: String -> (ModName,[ModName])-parseString = parse . lexerPass1+parseString = parse . dropApproxCPP . lexerPass1 +dropApproxCPP :: [PosToken] -> [PosToken]++ -- this is some artifact of the lexer+dropApproxCPP ((_, (_,"")) : more) = dropApproxCPP more++dropApproxCPP ((Varsym, (_,"#")) : (_, (pos,tok)) : more)+ | tok `elem` [ "if", "ifdef", "ifndef" ] = dropToEndif more+ | tok `elem` [ "include", "define", "undef" ] = dropToEOL more+ where+ dropToEndif ((Varsym, (_,"#")) : (_, (_,"endif")) : rest)+ = dropApproxCPP rest+ dropToEndif (_ : rest) = dropToEndif rest+ dropToEndif [] = []++ dropToEOL ((_, (pos1,_)) : rest)+ | line pos == line pos1 = dropToEOL rest+ dropToEOL xs = dropApproxCPP xs++dropApproxCPP (x : xs) = x : dropApproxCPP xs+dropApproxCPP [] = []++ isImp :: [PosToken] -> Maybe (String, [PosToken]) isImp (_ : (Conid, (_,x)) : xs) = Just (x,xs) isImp (_ : (Qconid, (_,x)) : xs) = Just (x,xs)@@ -37,7 +59,7 @@ isImp _ = Nothing parse :: [PosToken] -> (ModName,[ModName])-parse (_ : (Reservedid,(_,"module")) : (_,(_,m)) : is) =+parse ((Reservedid,(_,"module")) : (_,(_,m)) : is) = (splitModName m,imports is) parse is = (([],"Main"),imports is)