git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #382 from garyb/master

Docgen tweaks

commit6d15a7de20b6ce521cc96003cdcbd91a18db7317 authorGary Burgess <gary.burgess@gmail.com> dateMon 21 Apr 2014, 21:27 (13 years ago) parent90bf9abbb64a4a
4 files changed+39−117
docgen/Main.hs+37−26 docs/source/prelude.rst−45 prelude/README.md+1−45 prelude/updateDocs.sh+1−1
docgen/Main.hs+37−26
@@ -26,15 +26,15 @@ import qualified System.IO.UTF8 as U
2626import System.Console.CmdTheLine
2727import System.Exit (exitSuccess, exitFailure)
2828
29−docgen :: FilePath -> IO ()
30−docgen input = do
29+docgen :: FilePath -> Bool -> IO ()
30+docgen input showHierarchy = do
3131 text <- U.readFile input
3232 case P.runIndentParser input P.parseModules text of
3333 Left err -> do
3434 U.print err
3535 exitFailure
3636 Right ms -> do
37− U.putStrLn . runDocs $ renderModules ms
37+ U.putStrLn . runDocs $ (renderModules showHierarchy) ms
3838 exitSuccess
3939
4040type Docs = Writer [String] ()
@@ -53,37 +53,45 @@ atIndent indent text =
5353 let ls = lines text in
5454 forM_ ls $ \l -> tell [replicate indent ' ' ++ l]
5555
56−renderModules :: [P.Module] -> Docs
57−renderModules ms = do
56+renderModules :: Bool -> [P.Module] -> Docs
57+renderModules showHierarchy ms = do
5858 headerLevel 1 "Module Documentation"
59− mapM_ renderModule ms
59+ spacer
60+ mapM_ (renderModule showHierarchy) ms
6061
61−renderModule :: P.Module -> Docs
62−renderModule (P.Module moduleName ds exps) =
62+renderModule :: Bool -> P.Module -> Docs
63+renderModule showHierarchy (P.Module moduleName ds exps) =
6364 let exported = filter (isExported exps) ds
65+ hasTypes = any isTypeDeclaration ds
6466 hasTypeclasses = any isTypeClassDeclaration ds
67+ hasTypeclassInstances = any isTypeInstanceDeclaration ds
68+ hasValues = any isValueDeclaration ds
6569 in do
6670 headerLevel 2 $ "Module " ++ P.runModuleName moduleName
6771 spacer
68− headerLevel 3 "Types"
69− spacer
70− renderTopLevel exps (filter isTypeDeclaration exported)
71− spacer
72− headerLevel 3 "Type Classes"
73− spacer
72+ when hasTypes $ do
73+ headerLevel 3 "Types"
74+ spacer
75+ renderTopLevel exps (filter isTypeDeclaration exported)
76+ spacer
7477 when hasTypeclasses $ do
75− renderTypeclassImage moduleName
78+ headerLevel 3 "Type Classes"
79+ spacer
80+ when showHierarchy $ do
81+ renderTypeclassImage moduleName
82+ spacer
83+ renderTopLevel exps (filter isTypeClassDeclaration exported)
84+ spacer
85+ when hasTypeclassInstances $ do
86+ headerLevel 3 "Type Class Instances"
87+ spacer
88+ renderTopLevel exps (filter isTypeInstanceDeclaration ds)
89+ spacer
90+ when hasValues $ do
91+ headerLevel 3 "Values"
92+ spacer
93+ renderTopLevel exps (filter isValueDeclaration exported)
7694 spacer
77− renderTopLevel exps (filter isTypeClassDeclaration exported)
78− spacer
79− headerLevel 3 "Type Class Instances"
80− spacer
81− renderTopLevel exps (filter isTypeInstanceDeclaration ds)
82− spacer
83− headerLevel 3 "Values"
84− spacer
85− renderTopLevel exps (filter isValueDeclaration exported)
86− spacer
8795
8896isExported :: Maybe [P.DeclarationRef] -> P.Declaration -> Bool
8997isExported Nothing _ = True
@@ -185,8 +193,11 @@ isTypeInstanceDeclaration _ = False
185193inputFile :: Term FilePath
186194inputFile = value $ pos 0 "input.ps" $ posInfo { posDoc = "The input .ps file" }
187195
196+includeHeirarcy :: Term Bool
197+includeHeirarcy = value $ flag $ (optInfo [ "h", "hierarchy-images" ]) { optDoc = "Include markdown for type class hierarchy images in the output." }
198+
188199term :: Term (IO ())
189−term = docgen <$> inputFile
200+term = docgen <$> inputFile <*> includeHeirarcy
190201
191202termInfo :: TermInfo
192203termInfo = defTI
docs/source/prelude.rst−45
@@ -209,15 +209,6 @@ Values
209209Module Data.Function
210210--------------------
211211
212−Types
213−~~~~~
214−
215−Type Classes
216−~~~~~~~~~~~~
217−
218−Type Class Instances
219−~~~~~~~~~~~~~~~~~~~~
220−
221212Values
222213~~~~~~
223214
@@ -236,9 +227,6 @@ Types
236227 data Ref a where
237228 Ref :: a -> Ref a
238229
239−Type Classes
240−~~~~~~~~~~~~
241−
242230Type Class Instances
243231~~~~~~~~~~~~~~~~~~~~
244232
@@ -256,15 +244,6 @@ Values
256244Module Prelude.Unsafe
257245---------------------
258246
259−Types
260−~~~~~
261−
262−Type Classes
263−~~~~~~~~~~~~
264−
265−Type Class Instances
266−~~~~~~~~~~~~~~~~~~~~
267−
268247Values
269248~~~~~~
270249
@@ -284,9 +263,6 @@ Types
284263
285264 type Pure a = forall e. Eff e a
286265
287−Type Classes
288−~~~~~~~~~~~~
289−
290266Type Class Instances
291267~~~~~~~~~~~~~~~~~~~~
292268
@@ -324,15 +300,6 @@ Values
324300Module Control.Monad.Eff.Unsafe
325301-------------------------------
326302
327−Types
328−~~~~~
329−
330−Type Classes
331−~~~~~~~~~~~~
332−
333−Type Class Instances
334−~~~~~~~~~~~~~~~~~~~~
335−
336303Values
337304~~~~~~
338305
@@ -350,12 +317,6 @@ Types
350317
351318 data Trace :: !
352319
353−Type Classes
354−~~~~~~~~~~~~
355−
356−Type Class Instances
357−~~~~~~~~~~~~~~~~~~~~
358−
359320Values
360321~~~~~~
361322
@@ -379,12 +340,6 @@ Types
379340
380341 data STRef :: * -> * -> *
381342
382−Type Classes
383−~~~~~~~~~~~~
384−
385−Type Class Instances
386−~~~~~~~~~~~~~~~~~~~~
387−
388343Values
389344~~~~~~
390345
prelude/README.md+1−45
@@ -1,4 +1,5 @@
11# Module Documentation
2+
23## Module Prelude
34
45### Types
@@ -195,15 +196,6 @@
195196
196197## Module Data.Function
197198
198−### Types
199−
200−
201−### Type Classes
202−
203−
204−### Type Class Instances
205−
206−
207199### Values
208200
209201 on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
@@ -217,9 +209,6 @@
217209 Ref :: a -> Ref a
218210
219211
220−### Type Classes
221−
222−
223212### Type Class Instances
224213
225214 instance eqRef :: Eq (Ref a)
@@ -232,15 +221,6 @@
232221
233222## Module Prelude.Unsafe
234223
235−### Types
236−
237−
238−### Type Classes
239−
240−
241−### Type Class Instances
242−
243−
244224### Values
245225
246226 unsafeIndex :: forall a. [a] -> Prim.Number -> a
@@ -255,9 +235,6 @@
255235 type Pure a = forall e. Eff e a
256236
257237
258−### Type Classes
259−
260−
261238### Type Class Instances
262239
263240 instance applicativeEff :: Applicative (Eff e)
@@ -290,15 +267,6 @@
290267
291268## Module Control.Monad.Eff.Unsafe
292269
293−### Types
294−
295−
296−### Type Classes
297−
298−
299−### Type Class Instances
300−
301−
302270### Values
303271
304272 unsafeInterleaveEff :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a
@@ -311,12 +279,6 @@
311279 data Trace :: !
312280
313281
314−### Type Classes
315−
316−
317−### Type Class Instances
318−
319−
320282### Values
321283
322284 print :: forall a r. (Show a) => a -> Eff (trace :: Trace | r) { }
@@ -335,12 +297,6 @@
335297 data STRef :: * -> * -> *
336298
337299
338−### Type Classes
339−
340−
341−### Type Class Instances
342−
343−
344300### Values
345301
346302 modifySTRef :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
prelude/updateDocs.sh+1−1
@@ -1,4 +1,4 @@
1−../dist/build/docgen/docgen prelude.purs > README.md
1+../dist/build/docgen/docgen --hierarchy-images prelude.purs > README.md
22../dist/build/hierarchy/hierarchy prelude.purs -o prelude
33mkdir -p images
44mkdir -p ../docs/source/images