git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Render without sections
732e60eGary Burgess
psc-docs/Main.hs+23−61
@@ -43,7 +43,7 @@ docgen (PSCDocsOptions showHierarchy input) = do
43 hPutStrLn stderr $ show err
43 hPutStrLn stderr $ show err
44 exitFailure
44 exitFailure
45 Right ms -> do
45 Right ms -> do
46− putStrLn . runDocs $ (renderModules showHierarchy) (map snd ms)
46+ putStrLn . runDocs $ renderModules showHierarchy (map snd ms)
47 exitSuccess
47 exitSuccess
48
48
49parseFile :: FilePath -> IO (FilePath, String)
49parseFile :: FilePath -> IO (FilePath, String)
@@ -78,45 +78,19 @@ renderModules showHierarchy ms = do
78 mapM_ (renderModule showHierarchy) ms
78 mapM_ (renderModule showHierarchy) ms
79
79
80renderModule :: Bool -> P.Module -> Docs
80renderModule :: Bool -> P.Module -> Docs
81−renderModule showHierarchy mdl@(P.Module moduleName _ exps) =
81+renderModule showHierarchy mdl@(P.Module moduleName _ exps) = do
82− let ds = P.exportedDeclarations mdl
83− hasTypes = any isTypeDeclaration ds
84− hasTypeclasses = any isTypeClassDeclaration ds
85− hasTypeclassInstances = any isTypeInstanceDeclaration ds
86− hasValues = any isValueDeclaration ds
87− in do
88 headerLevel 2 $ "Module " ++ P.runModuleName moduleName
82 headerLevel 2 $ "Module " ++ P.runModuleName moduleName
89 spacer
83 spacer
90− when hasTypes $ do
91− headerLevel 3 "Types"
92− spacer
93− renderTopLevel exps (filter isTypeDeclaration ds)
94− spacer
95− when hasTypeclasses $ do
96− headerLevel 3 "Type Classes"
97− spacer
98− when showHierarchy $ do
99− renderTypeclassImage moduleName
100− spacer
101− renderTopLevel exps (filter isTypeClassDeclaration ds)
84+ renderTopLevel exps (P.exportedDeclarations mdl)
102− spacer
103− when hasTypeclassInstances $ do
104− headerLevel 3 "Type Class Instances"
105− spacer
106− renderTopLevel exps (filter isTypeInstanceDeclaration ds)
107− spacer
108− when hasValues $ do
109− headerLevel 3 "Values"
110− spacer
111− renderTopLevel exps (filter isValueDeclaration ds)
112− spacer
85+ spacer
113
86
114renderTopLevel :: Maybe [P.DeclarationRef] -> [P.Declaration] -> Docs
87renderTopLevel :: Maybe [P.DeclarationRef] -> [P.Declaration] -> Docs
115−renderTopLevel exps decls = forM_ decls $ \decl -> do
88+renderTopLevel exps decls = forM_ decls $ \decl ->
89+ when (canRenderDecl decl) $ do
116− traverse_ (headerLevel 4) (ticks `fmap` getDeclarationTitle decl)
90+ traverse_ (headerLevel 4) (ticks `fmap` getDeclarationTitle decl)
117− spacer
91+ spacer
118− renderDeclaration exps decl
92+ renderDeclaration exps decl
119− spacer
93+ spacer
120
94
121renderTypeclassImage :: P.ModuleName -> Docs
95renderTypeclassImage :: P.ModuleName -> Docs
122renderTypeclassImage name =
96renderTypeclassImage name =
@@ -222,41 +196,29 @@ getName (P.TypeInstanceDeclaration name _ _ _ _) = show name
222getName (P.PositionedDeclaration _ _ d) = getName d
196getName (P.PositionedDeclaration _ _ d) = getName d
223getName _ = error "Invalid argument to getName"
197getName _ = error "Invalid argument to getName"
224
198
225−isValueDeclaration :: P.Declaration -> Bool
199+canRenderDecl :: P.Declaration -> Bool
226−isValueDeclaration P.TypeDeclaration{} = True
200+canRenderDecl P.TypeDeclaration{} = True
227−isValueDeclaration P.ExternDeclaration{} = True
201+canRenderDecl P.ExternDeclaration{} = True
228−isValueDeclaration (P.PositionedDeclaration _ _ d) = isValueDeclaration d
229−isValueDeclaration _ = False
230−
231−isTypeDeclaration :: P.Declaration -> Bool
232−isTypeDeclaration P.DataDeclaration{} = True
202+canRenderDecl P.DataDeclaration{} = True
233−isTypeDeclaration P.ExternDataDeclaration{} = True
203+canRenderDecl P.ExternDataDeclaration{} = True
234−isTypeDeclaration P.TypeSynonymDeclaration{} = True
204+canRenderDecl P.TypeSynonymDeclaration{} = True
235−isTypeDeclaration (P.PositionedDeclaration _ _ d) = isTypeDeclaration d
236−isTypeDeclaration _ = False
237−
238−isTypeClassDeclaration :: P.Declaration -> Bool
239−isTypeClassDeclaration P.TypeClassDeclaration{} = True
205+canRenderDecl P.TypeClassDeclaration{} = True
240−isTypeClassDeclaration (P.PositionedDeclaration _ _ d) = isTypeClassDeclaration d
241−isTypeClassDeclaration _ = False
242−
243−isTypeInstanceDeclaration :: P.Declaration -> Bool
244−isTypeInstanceDeclaration P.TypeInstanceDeclaration{} = True
206+canRenderDecl P.TypeInstanceDeclaration{} = True
245−isTypeInstanceDeclaration (P.PositionedDeclaration _ _ d) = isTypeInstanceDeclaration d
207+canRenderDecl (P.PositionedDeclaration _ _ d) = canRenderDecl d
246−isTypeInstanceDeclaration _ = False
208+canRenderDecl _ = False
247
209
248inputFile :: Parser FilePath
210inputFile :: Parser FilePath
249inputFile = strArgument $
211inputFile = strArgument $
250 metavar "FILE"
212 metavar "FILE"
251 <> help "The input .purs file(s)"
213 <> help "The input .purs file(s)"
252
214
253−includeHeirarcy :: Parser Bool
215+includeHierarcy :: Parser Bool
254−includeHeirarcy = switch $
216+includeHierarcy = switch $
255 long "hierarchy-images"
217 long "hierarchy-images"
256 <> help "Include markdown for type class hierarchy images in the output."
218 <> help "Include markdown for type class hierarchy images in the output."
257
219
258pscDocsOptions :: Parser PSCDocsOptions
220pscDocsOptions :: Parser PSCDocsOptions
259−pscDocsOptions = PSCDocsOptions <$> includeHeirarcy
221+pscDocsOptions = PSCDocsOptions <$> includeHierarcy
260 <*> many inputFile
222 <*> many inputFile
261
223
262main :: IO ()
224main :: IO ()