git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #382 from garyb/master
6d15a7dGary Burgess
docgen/Main.hs+37−26
@@ -26,15 +26,15 @@ import qualified System.IO.UTF8 as U
26import System.Console.CmdTheLine
26import System.Console.CmdTheLine
27import System.Exit (exitSuccess, exitFailure)
27import System.Exit (exitSuccess, exitFailure)
28
28
29−docgen :: FilePath -> IO ()
29+docgen :: FilePath -> Bool -> IO ()
30−docgen input = do
30+docgen input showHierarchy = do
31 text <- U.readFile input
31 text <- U.readFile input
32 case P.runIndentParser input P.parseModules text of
32 case P.runIndentParser input P.parseModules text of
33 Left err -> do
33 Left err -> do
34 U.print err
34 U.print err
35 exitFailure
35 exitFailure
36 Right ms -> do
36 Right ms -> do
37− U.putStrLn . runDocs $ renderModules ms
37+ U.putStrLn . runDocs $ (renderModules showHierarchy) ms
38 exitSuccess
38 exitSuccess
39
39
40type Docs = Writer [String] ()
40type Docs = Writer [String] ()
@@ -53,37 +53,45 @@ atIndent indent text =
53 let ls = lines text in
53 let ls = lines text in
54 forM_ ls $ \l -> tell [replicate indent ' ' ++ l]
54 forM_ ls $ \l -> tell [replicate indent ' ' ++ l]
55
55
56−renderModules :: [P.Module] -> Docs
56+renderModules :: Bool -> [P.Module] -> Docs
57−renderModules ms = do
57+renderModules showHierarchy ms = do
58 headerLevel 1 "Module Documentation"
58 headerLevel 1 "Module Documentation"
59+ spacer
59− mapM_ renderModule ms
60+ mapM_ (renderModule showHierarchy) ms
60
61
61−renderModule :: P.Module -> Docs
62+renderModule :: Bool -> P.Module -> Docs
62−renderModule (P.Module moduleName ds exps) =
63+renderModule showHierarchy (P.Module moduleName ds exps) =
63 let exported = filter (isExported exps) ds
64 let exported = filter (isExported exps) ds
65+ hasTypes = any isTypeDeclaration ds
64 hasTypeclasses = any isTypeClassDeclaration ds
66 hasTypeclasses = any isTypeClassDeclaration ds
67+ hasTypeclassInstances = any isTypeInstanceDeclaration ds
68+ hasValues = any isValueDeclaration ds
65 in do
69 in do
66 headerLevel 2 $ "Module " ++ P.runModuleName moduleName
70 headerLevel 2 $ "Module " ++ P.runModuleName moduleName
67 spacer
71 spacer
72+ when hasTypes $ do
68− headerLevel 3 "Types"
73+ headerLevel 3 "Types"
69− spacer
74+ spacer
70− renderTopLevel exps (filter isTypeDeclaration exported)
75+ renderTopLevel exps (filter isTypeDeclaration exported)
71− spacer
72− headerLevel 3 "Type Classes"
73− spacer
76+ spacer
74 when hasTypeclasses $ do
77 when hasTypeclasses $ do
78+ headerLevel 3 "Type Classes"
79+ spacer
80+ when showHierarchy $ do
75− renderTypeclassImage moduleName
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)
76 spacer
94 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
87
95
88isExported :: Maybe [P.DeclarationRef] -> P.Declaration -> Bool
96isExported :: Maybe [P.DeclarationRef] -> P.Declaration -> Bool
89isExported Nothing _ = True
97isExported Nothing _ = True
@@ -185,8 +193,11 @@ isTypeInstanceDeclaration _ = False
185inputFile :: Term FilePath
193inputFile :: Term FilePath
186inputFile = value $ pos 0 "input.ps" $ posInfo { posDoc = "The input .ps file" }
194inputFile = value $ pos 0 "input.ps" $ posInfo { posDoc = "The input .ps file" }
187
195
196+includeHeirarcy :: Term Bool
197+includeHeirarcy = value $ flag $ (optInfo [ "h", "hierarchy-images" ]) { optDoc = "Include markdown for type class hierarchy images in the output." }
198+
188term :: Term (IO ())
199term :: Term (IO ())
189−term = docgen <$> inputFile
200+term = docgen <$> inputFile <*> includeHeirarcy
190
201
191termInfo :: TermInfo
202termInfo :: TermInfo
192termInfo = defTI
203termInfo = defTI
docs/source/prelude.rst−45
@@ -209,15 +209,6 @@ Values
209Module Data.Function
209Module Data.Function
210--------------------
210--------------------
211
211
212−Types
213−~~~~~
214−
215−Type Classes
216−~~~~~~~~~~~~
217−
218−Type Class Instances
219−~~~~~~~~~~~~~~~~~~~~
220−
221Values
212Values
222~~~~~~
213~~~~~~
223
214
@@ -236,9 +227,6 @@ Types
236 data Ref a where
227 data Ref a where
237 Ref :: a -> Ref a
228 Ref :: a -> Ref a
238
229
239−Type Classes
240−~~~~~~~~~~~~
241−
242Type Class Instances
230Type Class Instances
243~~~~~~~~~~~~~~~~~~~~
231~~~~~~~~~~~~~~~~~~~~
244
232
@@ -256,15 +244,6 @@ Values
256Module Prelude.Unsafe
244Module Prelude.Unsafe
257---------------------
245---------------------
258
246
259−Types
260−~~~~~
261−
262−Type Classes
263−~~~~~~~~~~~~
264−
265−Type Class Instances
266−~~~~~~~~~~~~~~~~~~~~
267−
268Values
247Values
269~~~~~~
248~~~~~~
270
249
@@ -284,9 +263,6 @@ Types
284
263
285 type Pure a = forall e. Eff e a
264 type Pure a = forall e. Eff e a
286
265
287−Type Classes
288−~~~~~~~~~~~~
289−
290Type Class Instances
266Type Class Instances
291~~~~~~~~~~~~~~~~~~~~
267~~~~~~~~~~~~~~~~~~~~
292
268
@@ -324,15 +300,6 @@ Values
324Module Control.Monad.Eff.Unsafe
300Module Control.Monad.Eff.Unsafe
325-------------------------------
301-------------------------------
326
302
327−Types
328−~~~~~
329−
330−Type Classes
331−~~~~~~~~~~~~
332−
333−Type Class Instances
334−~~~~~~~~~~~~~~~~~~~~
335−
336Values
303Values
337~~~~~~
304~~~~~~
338
305
@@ -350,12 +317,6 @@ Types
350
317
351 data Trace :: !
318 data Trace :: !
352
319
353−Type Classes
354−~~~~~~~~~~~~
355−
356−Type Class Instances
357−~~~~~~~~~~~~~~~~~~~~
358−
359Values
320Values
360~~~~~~
321~~~~~~
361
322
@@ -379,12 +340,6 @@ Types
379
340
380 data STRef :: * -> * -> *
341 data STRef :: * -> * -> *
381
342
382−Type Classes
383−~~~~~~~~~~~~
384−
385−Type Class Instances
386−~~~~~~~~~~~~~~~~~~~~
387−
388Values
343Values
389~~~~~~
344~~~~~~
390
345
prelude/README.md+1−45
@@ -1,4 +1,5 @@
1# Module Documentation
1# Module Documentation
2+
2## Module Prelude
3## Module Prelude
3
4
4### Types
5### Types
@@ -195,15 +196,6 @@
195
196
196## Module Data.Function
197## Module Data.Function
197
198
198−### Types
199−
200−
201−### Type Classes
202−
203−
204−### Type Class Instances
205−
206−
207### Values
199### Values
208
200
209 on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
201 on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
@@ -217,9 +209,6 @@
217 Ref :: a -> Ref a
209 Ref :: a -> Ref a
218
210
219
211
220−### Type Classes
221−
222−
223### Type Class Instances
212### Type Class Instances
224
213
225 instance eqRef :: Eq (Ref a)
214 instance eqRef :: Eq (Ref a)
@@ -232,15 +221,6 @@
232
221
233## Module Prelude.Unsafe
222## Module Prelude.Unsafe
234
223
235−### Types
236−
237−
238−### Type Classes
239−
240−
241−### Type Class Instances
242−
243−
244### Values
224### Values
245
225
246 unsafeIndex :: forall a. [a] -> Prim.Number -> a
226 unsafeIndex :: forall a. [a] -> Prim.Number -> a
@@ -255,9 +235,6 @@
255 type Pure a = forall e. Eff e a
235 type Pure a = forall e. Eff e a
256
236
257
237
258−### Type Classes
259−
260−
261### Type Class Instances
238### Type Class Instances
262
239
263 instance applicativeEff :: Applicative (Eff e)
240 instance applicativeEff :: Applicative (Eff e)
@@ -290,15 +267,6 @@
290
267
291## Module Control.Monad.Eff.Unsafe
268## Module Control.Monad.Eff.Unsafe
292
269
293−### Types
294−
295−
296−### Type Classes
297−
298−
299−### Type Class Instances
300−
301−
302### Values
270### Values
303
271
304 unsafeInterleaveEff :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a
272 unsafeInterleaveEff :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a
@@ -311,12 +279,6 @@
311 data Trace :: !
279 data Trace :: !
312
280
313
281
314−### Type Classes
315−
316−
317−### Type Class Instances
318−
319−
320### Values
282### Values
321
283
322 print :: forall a r. (Show a) => a -> Eff (trace :: Trace | r) { }
284 print :: forall a r. (Show a) => a -> Eff (trace :: Trace | r) { }
@@ -335,12 +297,6 @@
335 data STRef :: * -> * -> *
297 data STRef :: * -> * -> *
336
298
337
299
338−### Type Classes
339−
340−
341−### Type Class Instances
342−
343−
344### Values
300### Values
345
301
346 modifySTRef :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
302 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
2../dist/build/hierarchy/hierarchy prelude.purs -o prelude
2../dist/build/hierarchy/hierarchy prelude.purs -o prelude
3mkdir -p images
3mkdir -p images
4mkdir -p ../docs/source/images
4mkdir -p ../docs/source/images