This repository has been archived by the owner on Jul 29, 2024. It is now read-only.
forked from Haskell-Things/ImplicitCAD
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocgen.hs
46 lines (38 loc) · 1.55 KB
/
docgen.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
40
41
42
43
44
45
-- Implicit CAD. Copyright (C) 2011, Christopher Olah ([email protected])
-- Released under the GNU GPL, see LICENSE
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, FlexibleContexts, TypeSynonymInstances, UndecidableInstances, ScopedTypeVariables #-}
import Graphics.Implicit.ExtOpenScad.Primitives (primitives)
import Graphics.Implicit.ExtOpenScad.Util.ArgParser
import Control.Monad
isExample (ExampleDoc _ ) = True
isExample _ = False
isArgument (ArgumentDoc _ _ _) = True
isArgument _ = False
main = do
let names = map fst primitives
docs <- sequence $ map (getArgParserDocs.($ []).snd) primitives
forM_ (zip names docs) $ \(moduleName, moduleDocList) -> do
let
examples = filter isExample moduleDocList
arguments = filter isArgument moduleDocList
putStrLn moduleName
putStrLn (map (const '-') moduleName)
putStrLn ""
if not $ null examples then putStrLn "**Examples:**\n" else return ()
forM_ examples $ \(ExampleDoc example) -> do
putStrLn $ " * `" ++ example ++ "`"
putStrLn ""
putStrLn "**Arguments:**\n"
forM_ arguments $ \(ArgumentDoc name posfallback description) ->
case (posfallback, description) of
(Nothing, "") -> do
putStrLn $ " * `" ++ name ++ "`"
(Just fallback, "") -> do
putStrLn $ " * `" ++ name ++ " = " ++ fallback ++ "`"
(Nothing, _) -> do
putStrLn $ " * `" ++ name ++ "`"
putStrLn $ " " ++ description
(Just fallback, _) -> do
putStrLn $ " * `" ++ name ++ " = " ++ fallback ++ "`"
putStrLn $ " " ++ description
putStrLn ""