git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Made hierarchy more general.
abca996joneshf
hierarchy/Main.hs+25−9
@@ -16,11 +16,15 @@
16module Main where
16module Main where
17
17
18import Control.Applicative ((<*>), (<$>))
18import Control.Applicative ((<*>), (<$>))
19+import Control.Monad (unless)
19
20
20import Data.List (intercalate,nub,sort)
21import Data.List (intercalate,nub,sort)
22+import Data.Foldable (for_)
21import Data.Version (showVersion)
23import Data.Version (showVersion)
22
24
23import System.Console.CmdTheLine
25import System.Console.CmdTheLine
26+import System.Directory (createDirectoryIfMissing)
27+import System.FilePath ((</>))
24import System.Exit (exitFailure, exitSuccess)
28import System.Exit (exitFailure, exitSuccess)
25
29
26import Text.Parsec (ParseError)
30import Text.Parsec (ParseError)
@@ -41,6 +45,9 @@ instance Ord SuperMap where
41 where
45 where
42 getCls = either id snd
46 getCls = either id snd
43
47
48+runModuleName :: P.ModuleName -> String
49+runModuleName (P.ModuleName pns) = intercalate "_" (P.runProperName `map` pns)
50+
44readInput :: FilePath -> IO (Either ParseError [P.Module])
51readInput :: FilePath -> IO (Either ParseError [P.Module])
45readInput p = do
52readInput p = do
46 text <- U.readFile p
53 text <- U.readFile p
@@ -51,13 +58,21 @@ compile input mOutput = do
51 modules <- readInput input
58 modules <- readInput input
52 case modules of
59 case modules of
53 Left err -> U.print err >> exitFailure
60 Left err -> U.print err >> exitFailure
61+ Right ms -> do
54− Right (P.Module _ decls _ : _) -> do
62+ for_ ms $ \(P.Module moduleName decls _) ->
63+ let name = runModuleName moduleName
55− let tcs = filter P.isTypeClassDeclaration decls
64+ tcs = filter P.isTypeClassDeclaration decls
56− let supers = sort . nub . filter (not . null) $ fmap superClasses tcs
65+ supers = sort . nub . filter (not . null) $ fmap superClasses tcs
66+ prologue = "digraph " ++ name ++ " {\n"
57− let hier = "digraph Prelude {\n" ++ intercalate "\n" (concatMap (fmap ((" " ++) . (++ ";") . show)) supers) ++ "\n}"
67+ --body = intercalate "\n" (concatMap (fmap ((" " ++) . (++ ";") . show)) supers)
68+ body = intercalate "\n" (concatMap (fmap (\s -> " " ++ show s ++ ";")) supers)
69+ epilogue = "\n}"
70+ hier = prologue ++ body ++ epilogue
58− case mOutput of
71+ in unless (null supers) $ case mOutput of
72+ Just output -> do
73+ createDirectoryIfMissing True output
59− Just output -> U.writeFile output hier
74+ U.writeFile (output </> name) hier
60− Nothing -> U.putStrLn hier
75+ Nothing -> U.putStrLn hier
61 exitSuccess
76 exitSuccess
62
77
63superClasses :: P.Declaration -> [SuperMap]
78superClasses :: P.Declaration -> [SuperMap]
@@ -69,10 +84,11 @@ superClasses _ = []
69
84
70outputFile :: Term (Maybe FilePath)
85outputFile :: Term (Maybe FilePath)
71outputFile = value $ opt Nothing $ (optInfo [ "o", "output" ])
86outputFile = value $ opt Nothing $ (optInfo [ "o", "output" ])
72− { optDoc = "The output file" }
87+ { optDoc = "The output directory" }
73
88
74inputFile :: Term FilePath
89inputFile :: Term FilePath
90+inputFile = value $ pos 0 "main.purs" $ posInfo
75−inputFile = value $ pos 0 "main.purs" $ posInfo { posDoc = "The input file to generate a hierarchy from" }
91+ { posDoc = "The input file to generate a hierarchy from" }
76
92
77term :: Term (IO ())
93term :: Term (IO ())
78term = compile <$> inputFile <*> outputFile
94term = compile <$> inputFile <*> outputFile
prelude/updateDocs.sh+6−1
@@ -1,4 +1,9 @@
1../dist/build/docgen/docgen prelude.purs > README.md
1../dist/build/docgen/docgen prelude.purs > README.md
2+../dist/build/hierarchy/hierarchy prelude.purs -o prelude
2mkdir -p images
3mkdir -p images
4+for f in prelude/*; do
5+ BASE=$(basename "$f")
3−../dist/build/hierarchy/hierarchy prelude.purs | dot -Tpng -o images/Prelude.png
6+ dot -Tpng -o images/"$BASE".png "$f"
7+done
8+rm -r prelude
4pandoc -o ../docs/source/prelude.rst README.md
9pandoc -o ../docs/source/prelude.rst README.md
purescript.cabal+1−1
@@ -127,7 +127,7 @@ executable docgen
127
127
128executable hierarchy
128executable hierarchy
129 build-depends: base >=4 && <5, cmdtheline -any, purescript -any, utf8-string -any,
129 build-depends: base >=4 && <5, cmdtheline -any, purescript -any, utf8-string -any,
130− process -any, mtl -any, parsec -any
130+ process -any, mtl -any, parsec -any, filepath -any, directory -any
131 main-is: Main.hs
131 main-is: Main.hs
132 buildable: True
132 buildable: True
133 hs-source-dirs: hierarchy
133 hs-source-dirs: hierarchy