2021-12-15 08:24:49 +00:00
|
|
|
/-
|
|
|
|
Copyright (c) 2021 Henrik Böving. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
Authors: Henrik Böving
|
|
|
|
-/
|
|
|
|
import DocGen4.Output.Template
|
2022-01-03 17:22:12 +00:00
|
|
|
import DocGen4.Output.Inductive
|
2022-01-04 07:23:39 +00:00
|
|
|
import DocGen4.Output.Structure
|
2022-01-06 13:28:41 +00:00
|
|
|
import DocGen4.Output.Class
|
2022-02-02 10:22:15 +00:00
|
|
|
import DocGen4.Output.Definition
|
2022-02-04 21:48:08 +00:00
|
|
|
import DocGen4.Output.Instance
|
2022-02-06 19:14:36 +00:00
|
|
|
import DocGen4.Output.ClassInductive
|
2021-12-15 08:24:49 +00:00
|
|
|
|
|
|
|
namespace DocGen4
|
|
|
|
namespace Output
|
|
|
|
|
|
|
|
open scoped DocGen4.Jsx
|
2022-01-03 17:22:12 +00:00
|
|
|
open Lean
|
2021-12-25 13:08:09 +00:00
|
|
|
|
2021-12-25 15:55:30 +00:00
|
|
|
def argToHtml (arg : Arg) : HtmlM Html := do
|
|
|
|
let (l, r, implicit) := match arg.binderInfo with
|
|
|
|
| BinderInfo.default => ("(", ")", false)
|
|
|
|
| BinderInfo.implicit => ("{", "}", true)
|
|
|
|
| BinderInfo.strictImplicit => ("⦃", "⦄", true)
|
|
|
|
| BinderInfo.instImplicit => ("[", "]", true)
|
|
|
|
-- TODO: Can this ever be reached here? What does it mean?
|
|
|
|
| BinderInfo.auxDecl => unreachable!
|
|
|
|
let mut nodes := #[Html.text s!"{l}{arg.name.toString} : "]
|
|
|
|
nodes := nodes.append (←infoFormatToHtml arg.type)
|
|
|
|
nodes := nodes.push r
|
|
|
|
let inner := Html.element "span" true #[("class", "fn")] nodes
|
|
|
|
let html := Html.element "span" false #[("class", "decl_args")] #[inner]
|
|
|
|
if implicit then
|
2022-02-12 14:09:13 +00:00
|
|
|
pure <span «class»="impl_arg">{html}</span>
|
2021-12-25 15:55:30 +00:00
|
|
|
else
|
2022-02-12 14:09:13 +00:00
|
|
|
pure html
|
2021-12-25 15:55:30 +00:00
|
|
|
|
2022-01-04 07:23:39 +00:00
|
|
|
def structureInfoHeader (s : StructureInfo) : HtmlM (Array Html) := do
|
|
|
|
let mut nodes := #[]
|
|
|
|
if s.parents.size > 0 then
|
|
|
|
nodes := nodes.push <span «class»="decl_extends">extends</span>
|
|
|
|
let mut parents := #[]
|
|
|
|
for parent in s.parents do
|
|
|
|
let link := <a «class»="break_within" href={←declNameToLink parent}>{parent.toString}</a>
|
|
|
|
let inner := Html.element "span" true #[("class", "fn")] #[link]
|
|
|
|
let html:= Html.element "span" false #[("class", "decl_parent")] #[inner]
|
|
|
|
parents := parents.push html
|
|
|
|
nodes := nodes.append (parents.toList.intersperse (Html.text ", ")).toArray
|
2022-02-12 14:09:13 +00:00
|
|
|
pure nodes
|
2022-01-04 07:23:39 +00:00
|
|
|
|
2021-12-17 14:59:43 +00:00
|
|
|
def docInfoHeader (doc : DocInfo) : HtmlM Html := do
|
|
|
|
let mut nodes := #[]
|
2022-02-06 16:06:22 +00:00
|
|
|
nodes := nodes.push <span «class»="decl_kind">{doc.getKindDescription}</span>
|
2021-12-17 16:20:44 +00:00
|
|
|
nodes := nodes.push
|
|
|
|
<span «class»="decl_name">
|
|
|
|
<a «class»="break_within" href={←declNameToLink doc.getName}>
|
|
|
|
-- TODO: HTMLify the name
|
|
|
|
{doc.getName.toString}
|
|
|
|
</a>
|
|
|
|
</span>
|
2021-12-25 15:55:30 +00:00
|
|
|
for arg in doc.getArgs do
|
|
|
|
nodes := nodes.push (←argToHtml arg)
|
2022-01-04 07:23:39 +00:00
|
|
|
|
2022-01-06 13:28:41 +00:00
|
|
|
-- TODO: dedup this
|
|
|
|
match doc with
|
|
|
|
| DocInfo.structureInfo i => nodes := nodes.append (←structureInfoHeader i)
|
|
|
|
| DocInfo.classInfo i => nodes := nodes.append (←structureInfoHeader i.toStructureInfo)
|
|
|
|
| _ => nodes := nodes
|
2022-01-04 07:23:39 +00:00
|
|
|
|
2021-12-17 14:59:43 +00:00
|
|
|
nodes := nodes.push <span «class»="decl_args">:</span>
|
2021-12-25 13:08:09 +00:00
|
|
|
nodes := nodes.push $ Html.element "div" true #[("class", "decl_type")] (←infoFormatToHtml doc.getType)
|
2022-02-12 14:09:13 +00:00
|
|
|
pure <div «class»="decl_header"> [nodes] </div>
|
2021-12-15 08:24:49 +00:00
|
|
|
|
2022-01-09 15:57:19 +00:00
|
|
|
def docInfoToHtml (module : Name) (doc : DocInfo) : HtmlM Html := do
|
2022-02-13 02:32:53 +00:00
|
|
|
let docHtml ← match doc with
|
2022-01-03 17:22:12 +00:00
|
|
|
| DocInfo.inductiveInfo i => inductiveToHtml i
|
2022-01-04 07:23:39 +00:00
|
|
|
| DocInfo.structureInfo i => structureToHtml i
|
2022-01-06 13:28:41 +00:00
|
|
|
| DocInfo.classInfo i => classToHtml i
|
2022-02-02 10:22:15 +00:00
|
|
|
| DocInfo.definitionInfo i => definitionToHtml i
|
2022-02-04 21:48:08 +00:00
|
|
|
| DocInfo.instanceInfo i => instanceToHtml i
|
2022-02-06 19:14:36 +00:00
|
|
|
| DocInfo.classInductiveInfo i => classInductiveToHtml i
|
2022-02-12 14:09:13 +00:00
|
|
|
| _ => pure #[]
|
|
|
|
|
2022-02-13 02:32:53 +00:00
|
|
|
let attrs := doc.getAttrs
|
|
|
|
let attrsHtml :=
|
|
|
|
if attrs.size > 0 then
|
|
|
|
let attrStr := "@[" ++ String.intercalate ", " doc.getAttrs.toList ++ "]"
|
|
|
|
#[Html.element "div" false #[("class", "attributes")] #[attrStr]]
|
|
|
|
else
|
|
|
|
#[]
|
|
|
|
|
2022-02-12 14:09:13 +00:00
|
|
|
pure
|
|
|
|
<div «class»="decl" id={doc.getName.toString}>
|
|
|
|
<div «class»={doc.getKind}>
|
|
|
|
<div «class»="gh_link">
|
|
|
|
<a href={←getSourceUrl module doc.getDeclarationRange}>source</a>
|
|
|
|
</div>
|
2022-02-13 02:32:53 +00:00
|
|
|
[attrsHtml]
|
2022-02-12 14:09:13 +00:00
|
|
|
{←docInfoHeader doc}
|
2022-02-13 02:32:53 +00:00
|
|
|
[docHtml]
|
2021-12-15 10:59:36 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2022-01-16 13:22:53 +00:00
|
|
|
def declarationToNavLink (module : Name) : Html :=
|
2022-01-07 16:43:49 +00:00
|
|
|
<div «class»="nav_link">
|
|
|
|
<a «class»="break_within" href={s!"#{module.toString}"}>{module.toString}</a>
|
|
|
|
</div>
|
|
|
|
|
2022-01-16 13:22:53 +00:00
|
|
|
-- TODO: Similar functions are used all over the place, we should dedup them
|
|
|
|
def moduleToNavLink (module : Name) : HtmlM Html := do
|
2022-02-12 14:09:13 +00:00
|
|
|
pure <a href={←moduleNameToLink module}>{module.toString}</a>
|
2022-01-16 13:22:53 +00:00
|
|
|
|
|
|
|
def getImports (module : Name) : HtmlM (Array Name) := do
|
|
|
|
let res ← getResult
|
2022-02-12 14:09:13 +00:00
|
|
|
let some idx := res.moduleNames.findIdx? (. == module) | unreachable!
|
2022-01-16 13:22:53 +00:00
|
|
|
let adj := res.importAdj.get! idx
|
|
|
|
let mut imports := #[]
|
|
|
|
for i in [:adj.size] do
|
|
|
|
if adj.get! i then
|
|
|
|
imports := imports.push (res.moduleNames.get! i)
|
2022-02-12 14:09:13 +00:00
|
|
|
pure imports
|
2022-01-16 13:22:53 +00:00
|
|
|
|
|
|
|
def getImportedBy (module : Name) : HtmlM (Array Name) := do
|
|
|
|
let res ← getResult
|
2022-02-12 14:09:13 +00:00
|
|
|
let some idx := res.moduleNames.findIdx? (. == module) | unreachable!
|
2022-01-16 13:22:53 +00:00
|
|
|
let adj := res.importAdj
|
|
|
|
let mut impBy := #[]
|
|
|
|
for i in [:adj.size] do
|
|
|
|
if adj.get! i |>.get! idx then
|
|
|
|
impBy := impBy.push (res.moduleNames.get! i)
|
2022-02-12 14:09:13 +00:00
|
|
|
pure impBy
|
2022-01-16 13:22:53 +00:00
|
|
|
|
|
|
|
def importedByHtml (moduleName : Name) : HtmlM (Array Html) := do
|
|
|
|
let imports := (←getImportedBy moduleName) |>.qsort Name.lt
|
2022-02-12 14:09:13 +00:00
|
|
|
imports.mapM (λ i => do pure <li>{←moduleToNavLink i}</li>)
|
2022-01-16 13:22:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
def importsHtml (moduleName : Name) : HtmlM (Array Html) := do
|
|
|
|
let imports := (←getImports moduleName) |>.qsort Name.lt
|
2022-02-12 14:09:13 +00:00
|
|
|
imports.mapM (λ i => do pure <li>{←moduleToNavLink i}</li>)
|
2022-01-16 13:22:53 +00:00
|
|
|
|
2022-01-09 15:57:19 +00:00
|
|
|
def internalNav (members : Array Name) (moduleName : Name) : HtmlM Html := do
|
2022-02-12 14:09:13 +00:00
|
|
|
pure
|
|
|
|
<nav «class»="internal_nav">
|
|
|
|
<h3><a «class»="break_within" href="#top">{moduleName.toString}</a></h3>
|
|
|
|
<p «class»="gh_nav_link"><a href={←getSourceUrl moduleName none}>source</a></p>
|
|
|
|
<div «class»="imports">
|
|
|
|
<details>
|
|
|
|
<summary>Imports</summary>
|
|
|
|
<ul>
|
|
|
|
[←importsHtml moduleName]
|
|
|
|
</ul>
|
|
|
|
</details>
|
|
|
|
<details>
|
|
|
|
<summary>Imported by</summary>
|
|
|
|
<ul>
|
|
|
|
[←importedByHtml moduleName]
|
|
|
|
</ul>
|
|
|
|
</details>
|
|
|
|
</div>
|
|
|
|
[members.map declarationToNavLink]
|
|
|
|
</nav>
|
2022-01-07 16:43:49 +00:00
|
|
|
|
2021-12-15 08:24:49 +00:00
|
|
|
def moduleToHtml (module : Module) : HtmlM Html := withReader (setCurrentName module.name) do
|
2022-01-09 15:57:19 +00:00
|
|
|
let docInfos ← module.members.mapM (λ i => docInfoToHtml module.name i)
|
2022-02-12 14:09:13 +00:00
|
|
|
templateExtends (baseHtmlArray module.name.toString) $ pure #[
|
2022-01-09 15:57:19 +00:00
|
|
|
←internalNav (module.members.map DocInfo.getName) module.name,
|
2021-12-25 13:08:09 +00:00
|
|
|
Html.element "main" false #[] docInfos
|
2022-01-07 16:43:49 +00:00
|
|
|
]
|
2021-12-15 08:24:49 +00:00
|
|
|
|
|
|
|
end Output
|
|
|
|
end DocGen4
|