feat: class inductives
parent
27f8b50763
commit
8059940c30
|
@ -10,8 +10,8 @@ open Lean
|
||||||
def classInstanceToHtml (name : Name) : HtmlM Html := do
|
def classInstanceToHtml (name : Name) : HtmlM Html := do
|
||||||
<li><a href={←declNameToLink name}>{name.toString}</a></li>
|
<li><a href={←declNameToLink name}>{name.toString}</a></li>
|
||||||
|
|
||||||
def classInstancesToHtml (i : ClassInfo) : HtmlM Html := do
|
def classInstancesToHtml (instances : Array Name) : HtmlM Html := do
|
||||||
let instancesHtml ← i.instances.mapM classInstanceToHtml
|
let instancesHtml ← instances.mapM classInstanceToHtml
|
||||||
return <details «class»="instances">
|
return <details «class»="instances">
|
||||||
<summary>Instances</summary>
|
<summary>Instances</summary>
|
||||||
<ul>
|
<ul>
|
||||||
|
@ -20,7 +20,7 @@ def classInstancesToHtml (i : ClassInfo) : HtmlM Html := do
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
def classToHtml (i : ClassInfo) : HtmlM (Array Html) := do
|
def classToHtml (i : ClassInfo) : HtmlM (Array Html) := do
|
||||||
(←structureToHtml i.toStructureInfo).push (←classInstancesToHtml i)
|
(←structureToHtml i.toStructureInfo).push (←classInstancesToHtml i.instances)
|
||||||
|
|
||||||
end Output
|
end Output
|
||||||
end DocGen4
|
end DocGen4
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
import DocGen4.Output.Template
|
||||||
|
import DocGen4.Output.Class
|
||||||
|
import DocGen4.Output.Inductive
|
||||||
|
|
||||||
|
|
||||||
|
namespace DocGen4
|
||||||
|
namespace Output
|
||||||
|
|
||||||
|
def classInductiveToHtml (i : ClassInductiveInfo) : HtmlM (Array Html) := do
|
||||||
|
(←inductiveToHtml i.toInductiveInfo).push (←classInstancesToHtml i.instances)
|
||||||
|
|
||||||
|
end Output
|
||||||
|
end DocGen4
|
|
@ -9,6 +9,7 @@ import DocGen4.Output.Structure
|
||||||
import DocGen4.Output.Class
|
import DocGen4.Output.Class
|
||||||
import DocGen4.Output.Definition
|
import DocGen4.Output.Definition
|
||||||
import DocGen4.Output.Instance
|
import DocGen4.Output.Instance
|
||||||
|
import DocGen4.Output.ClassInductive
|
||||||
|
|
||||||
namespace DocGen4
|
namespace DocGen4
|
||||||
namespace Output
|
namespace Output
|
||||||
|
@ -77,6 +78,7 @@ def docInfoToHtml (module : Name) (doc : DocInfo) : HtmlM Html := do
|
||||||
| DocInfo.classInfo i => classToHtml i
|
| DocInfo.classInfo i => classToHtml i
|
||||||
| DocInfo.definitionInfo i => definitionToHtml i
|
| DocInfo.definitionInfo i => definitionToHtml i
|
||||||
| DocInfo.instanceInfo i => instanceToHtml i
|
| DocInfo.instanceInfo i => instanceToHtml i
|
||||||
|
| DocInfo.classInductiveInfo i => classInductiveToHtml i
|
||||||
| _ => #[]
|
| _ => #[]
|
||||||
|
|
||||||
return <div «class»="decl" id={doc.getName.toString}>
|
return <div «class»="decl" id={doc.getName.toString}>
|
||||||
|
|
|
@ -69,6 +69,10 @@ structure ClassInfo extends StructureInfo where
|
||||||
instances : Array Name
|
instances : Array Name
|
||||||
deriving Inhabited
|
deriving Inhabited
|
||||||
|
|
||||||
|
structure ClassInductiveInfo extends InductiveInfo where
|
||||||
|
instances : Array Name
|
||||||
|
deriving Inhabited
|
||||||
|
|
||||||
inductive DocInfo where
|
inductive DocInfo where
|
||||||
| axiomInfo (info : AxiomInfo) : DocInfo
|
| axiomInfo (info : AxiomInfo) : DocInfo
|
||||||
| theoremInfo (info : TheoremInfo) : DocInfo
|
| theoremInfo (info : TheoremInfo) : DocInfo
|
||||||
|
@ -78,6 +82,7 @@ inductive DocInfo where
|
||||||
| inductiveInfo (info : InductiveInfo) : DocInfo
|
| inductiveInfo (info : InductiveInfo) : DocInfo
|
||||||
| structureInfo (info : StructureInfo) : DocInfo
|
| structureInfo (info : StructureInfo) : DocInfo
|
||||||
| classInfo (info : ClassInfo) : DocInfo
|
| classInfo (info : ClassInfo) : DocInfo
|
||||||
|
| classInductiveInfo (info : ClassInductiveInfo) : DocInfo
|
||||||
deriving Inhabited
|
deriving Inhabited
|
||||||
|
|
||||||
namespace DocInfo
|
namespace DocInfo
|
||||||
|
@ -91,6 +96,7 @@ def getDeclarationRange : DocInfo → DeclarationRange
|
||||||
| inductiveInfo i => i.declarationRange
|
| inductiveInfo i => i.declarationRange
|
||||||
| structureInfo i => i.declarationRange
|
| structureInfo i => i.declarationRange
|
||||||
| classInfo i => i.declarationRange
|
| classInfo i => i.declarationRange
|
||||||
|
| classInductiveInfo i => i.declarationRange
|
||||||
|
|
||||||
def lineOrder (l r : DocInfo) : Bool :=
|
def lineOrder (l r : DocInfo) : Bool :=
|
||||||
l.getDeclarationRange.pos.line < r.getDeclarationRange.pos.line
|
l.getDeclarationRange.pos.line < r.getDeclarationRange.pos.line
|
||||||
|
@ -253,12 +259,19 @@ def StructureInfo.ofInductiveVal (v : InductiveVal) : MetaM StructureInfo := do
|
||||||
return StructureInfo.mk info #[] parents ⟨ctor.name, ctorType⟩
|
return StructureInfo.mk info #[] parents ⟨ctor.name, ctorType⟩
|
||||||
| none => panic! s!"{v.name} is not a structure"
|
| none => panic! s!"{v.name} is not a structure"
|
||||||
|
|
||||||
def ClassInfo.ofInductiveVal (v : InductiveVal) : MetaM ClassInfo := do
|
def getInstances (className : Name) : MetaM (Array Name) := do
|
||||||
let sinfo ← StructureInfo.ofInductiveVal v
|
let fn ← mkConstWithFreshMVarLevels className
|
||||||
let fn ← mkConstWithFreshMVarLevels v.name
|
|
||||||
let (xs, _, _) ← forallMetaTelescopeReducing (← inferType fn)
|
let (xs, _, _) ← forallMetaTelescopeReducing (← inferType fn)
|
||||||
let insts ← SynthInstance.getInstances (mkAppN fn xs)
|
let insts ← SynthInstance.getInstances (mkAppN fn xs)
|
||||||
return ClassInfo.mk sinfo (insts.map Expr.constName!)
|
insts.map Expr.constName!
|
||||||
|
|
||||||
|
def ClassInfo.ofInductiveVal (v : InductiveVal) : MetaM ClassInfo := do
|
||||||
|
let sinfo ← StructureInfo.ofInductiveVal v
|
||||||
|
return ClassInfo.mk sinfo (←getInstances v.name)
|
||||||
|
|
||||||
|
def ClassInductiveInfo.ofInductiveVal (v : InductiveVal) : MetaM ClassInductiveInfo := do
|
||||||
|
let info ← InductiveInfo.ofInductiveVal v
|
||||||
|
return ClassInductiveInfo.mk info (←getInstances v.name)
|
||||||
|
|
||||||
namespace DocInfo
|
namespace DocInfo
|
||||||
|
|
||||||
|
@ -314,7 +327,10 @@ def ofConstant : (Name × ConstantInfo) → MetaM (Option DocInfo) := λ (name,
|
||||||
else
|
else
|
||||||
some $ structureInfo (←StructureInfo.ofInductiveVal i)
|
some $ structureInfo (←StructureInfo.ofInductiveVal i)
|
||||||
else
|
else
|
||||||
some $ inductiveInfo (←InductiveInfo.ofInductiveVal i)
|
if isClass env i.name then
|
||||||
|
some $ classInductiveInfo (←ClassInductiveInfo.ofInductiveVal i)
|
||||||
|
else
|
||||||
|
some $ inductiveInfo (←InductiveInfo.ofInductiveVal i)
|
||||||
-- we ignore these for now
|
-- we ignore these for now
|
||||||
| ConstantInfo.ctorInfo i => none
|
| ConstantInfo.ctorInfo i => none
|
||||||
| ConstantInfo.recInfo i => none
|
| ConstantInfo.recInfo i => none
|
||||||
|
@ -329,6 +345,7 @@ def getName : DocInfo → Name
|
||||||
| inductiveInfo i => i.name
|
| inductiveInfo i => i.name
|
||||||
| structureInfo i => i.name
|
| structureInfo i => i.name
|
||||||
| classInfo i => i.name
|
| classInfo i => i.name
|
||||||
|
| classInductiveInfo i => i.name
|
||||||
|
|
||||||
def getKind : DocInfo → String
|
def getKind : DocInfo → String
|
||||||
| axiomInfo _ => "axiom"
|
| axiomInfo _ => "axiom"
|
||||||
|
@ -339,6 +356,7 @@ def getKind : DocInfo → String
|
||||||
| inductiveInfo _ => "inductive"
|
| inductiveInfo _ => "inductive"
|
||||||
| structureInfo _ => "structure"
|
| structureInfo _ => "structure"
|
||||||
| classInfo _ => "class"
|
| classInfo _ => "class"
|
||||||
|
| classInductiveInfo _ => "class"
|
||||||
|
|
||||||
def getKindDescription : DocInfo → String
|
def getKindDescription : DocInfo → String
|
||||||
| axiomInfo i => if i.isUnsafe then "unsafe axiom" else "axiom"
|
| axiomInfo i => if i.isUnsafe then "unsafe axiom" else "axiom"
|
||||||
|
@ -359,6 +377,7 @@ def getKindDescription : DocInfo → String
|
||||||
| inductiveInfo i => if i.isUnsafe then "unsafe inductive" else "inductive"
|
| inductiveInfo i => if i.isUnsafe then "unsafe inductive" else "inductive"
|
||||||
| structureInfo _ => "structure"
|
| structureInfo _ => "structure"
|
||||||
| classInfo _ => "class"
|
| classInfo _ => "class"
|
||||||
|
| classInductiveInfo _ => "class inductive"
|
||||||
|
|
||||||
def getType : DocInfo → CodeWithInfos
|
def getType : DocInfo → CodeWithInfos
|
||||||
| axiomInfo i => i.type
|
| axiomInfo i => i.type
|
||||||
|
@ -369,6 +388,7 @@ def getType : DocInfo → CodeWithInfos
|
||||||
| inductiveInfo i => i.type
|
| inductiveInfo i => i.type
|
||||||
| structureInfo i => i.type
|
| structureInfo i => i.type
|
||||||
| classInfo i => i.type
|
| classInfo i => i.type
|
||||||
|
| classInductiveInfo i => i.type
|
||||||
|
|
||||||
def getArgs : DocInfo → Array Arg
|
def getArgs : DocInfo → Array Arg
|
||||||
| axiomInfo i => i.args
|
| axiomInfo i => i.args
|
||||||
|
@ -379,6 +399,7 @@ def getArgs : DocInfo → Array Arg
|
||||||
| inductiveInfo i => i.args
|
| inductiveInfo i => i.args
|
||||||
| structureInfo i => i.args
|
| structureInfo i => i.args
|
||||||
| classInfo i => i.args
|
| classInfo i => i.args
|
||||||
|
| classInductiveInfo i => i.args
|
||||||
|
|
||||||
end DocInfo
|
end DocInfo
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue