-
Notifications
You must be signed in to change notification settings - Fork 3
/
coqdeps_as_dot.hs
39 lines (30 loc) · 1.3 KB
/
coqdeps_as_dot.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{-# LANGUAGE PatternGuards #-}
import Data.List (nub, (\\))
import Data.Map (Map)
import qualified Data.Map as Map
none :: (a -> Bool) -> [a] -> Bool
none p = all (not . p)
hide :: [String]
hide = words "util c_util list_util"
main :: IO ()
main = interact $ \s ->
let
reported_deps_map :: Map String [String]
reported_deps_map = Map.fromList $ map parse_line $ lines s
reported_deps :: String -> [String]
reported_deps n = Map.findWithDefault [] n reported_deps_map
names :: [String]
names = Map.keys reported_deps_map \\ hide
deep_deps_map :: Map String [String]
deep_deps_map = Map.fromList $ map (\n -> (n, let r = reported_deps n in r ++ concatMap deep_deps r)) names
deep_deps :: String -> [String]
deep_deps n = Map.findWithDefault [] n deep_deps_map
all_deps = concatMap (\n -> map (\d -> (n, d)) (deep_deps n)) names
depends_on x y = y `elem` deep_deps x
deps = [(x, y) | (x, y) <- all_deps, none (\n -> x `depends_on` n && n `depends_on` y) (names \\ [x, y])]
in
unlines $ ["digraph {"] ++ map (\(x, y) -> "\"" ++ x ++ "\" -> \"" ++ y ++ "\"") deps ++ ["}"]
where
parse_line :: String -> (String, [String])
parse_line l | (x, (_:xs)) <- span (/= ':') l = (strip_suffix x, map strip_suffix (tail $ words xs) \\ hide)
strip_suffix = takeWhile (/= '.')