-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathmkdocs.metta
More file actions
60 lines (54 loc) · 2.5 KB
/
Copy pathmkdocs.metta
File metadata and controls
60 lines (54 loc) · 2.5 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(: concat-help (-> String Expression Atom String))
(= (concat-help $text $expr $func)
(if (noreduce-eq $expr ())
$text
(let $head (car-atom $expr)
(let $tail (cdr-atom $expr)
(let $cur-text ($func $head)
(let $next-text (format-args "{}{}" ($text $cur-text))
(concat-help $next-text $tail $func) ))))))
(: help-md! (-> SpaceType Atom String))
(= (help-md! $space $atom)
(case (get-doc $space $atom) (
((@doc-formal (@item $item) (@kind function) (@type $type) (@desc $descr)
(@params $params)
(@return (@type $ret-type) (@desc $ret-desc)))
(let $h (format-args "## {}\n**Type**<br>\n`{}`<br>\n**Description**<br>\n{}<br>\n" ($item $type $descr))
(let $ph (format-args "**Parameters**<br>\n" ())
(let $ps (concat-help "" $params help-param-md!)
(let $r (format-args "**Returns**<br>\n`{}` {}\n" ($ret-type $ret-desc))
(format-args "{}{}{}{}" ($h $ph $ps $r) ))))))
((@doc-formal (@item $item) (@kind function) (@type $type) (@desc $descr))
(format-args "## {}\n**Type**<br>\n`{}`<br>\n**Description**<br>\n{}" ($item $type $descr)))
((@doc-formal (@item $item) (@kind atom) (@type $type) (@desc $descr))
(let $text (format-args "## {}\n**Type**<br>\n`{}`<br>\n**Description**<br>\n{}" ($item $type $descr)) $text))
($other (Error $other "Cannot match @doc-formal structure")) )))
(: help-param-md! (-> Atom String))
(= (help-param-md! $param)
(let (@param (@type $type) (@desc $desc)) $param
(format-args "`{}` - {}<br>\n" ($type $desc)) ))
(: help-md-space! (-> SpaceType String))
(= (help-md-space! $space)
(unify $space (@doc $name (@desc $desc) $params $ret)
(help-md! $space $name)
Empty ))
(= (help-md-space! $space)
(unify $space (@doc $name (@desc $desc))
(help-md! $space $name)
Empty ))
!(import! &self fileio)
(= (document-module $title $mod)
(let $_ (import! &self $mod)
(let $helps (collapse (help-md-space! (module-space-no-deps (mod-space! $mod))))
(let $sorted (sort-strings $helps)
(let $text (foldl-atom $sorted "" $r $i (format-args "{}{}" ($r $i)))
(let $md (format-args "# {}\n{}" ($title $text))
(let $path (format-args "./docs/generated/{}.md" ($mod))
(let $file (file-open! $path "wct")
(file-write! $file $md) ))))))))
!(document-module "Standard library" corelib)
!(document-module "Random" random)
!(document-module "File Input/Output" fileio)
!(document-module "JSON" json)
!(document-module "Module catalog" catalog)
!(document-module "DAS" das)