2022-05-19 22:36:21 +00:00
|
|
|
/-
|
|
|
|
Copyright (c) 2022 Henrik Böving. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
Authors: Henrik Böving
|
|
|
|
-/
|
|
|
|
import Lean
|
|
|
|
|
|
|
|
import DocGen4.Process.Base
|
|
|
|
import DocGen4.Process.NameInfo
|
|
|
|
import DocGen4.Process.DefinitionInfo
|
|
|
|
|
|
|
|
namespace DocGen4.Process
|
|
|
|
|
2022-07-23 13:40:08 +00:00
|
|
|
open Lean Meta
|
|
|
|
|
|
|
|
def getInstanceTypes (typ : Expr) : MetaM (Array Name) := do
|
|
|
|
let (_, _, tail) ← forallMetaTelescopeReducing typ
|
|
|
|
let args := tail.getAppArgs
|
2022-11-20 10:47:53 +00:00
|
|
|
let (_, names) ← args.mapM (Expr.forEach · findName) |>.run .empty
|
|
|
|
return names
|
2022-07-23 13:40:08 +00:00
|
|
|
where
|
|
|
|
findName : Expr → StateRefT (Array Name) MetaM Unit
|
2022-11-20 10:47:53 +00:00
|
|
|
| .const name _ => modify (·.push name)
|
|
|
|
| .sort .zero => modify (·.push "_builtin_prop")
|
|
|
|
| .sort (.succ _) => modify (·.push "_builtin_typeu")
|
|
|
|
| .sort _ => modify (·.push "_builtin_sortu")
|
2023-01-01 18:30:28 +00:00
|
|
|
| _ => return ()
|
2022-05-19 22:36:21 +00:00
|
|
|
|
|
|
|
def InstanceInfo.ofDefinitionVal (v : DefinitionVal) : MetaM InstanceInfo := do
|
2022-07-23 11:37:17 +00:00
|
|
|
let mut info ← DefinitionInfo.ofDefinitionVal v
|
2022-08-09 21:30:43 +00:00
|
|
|
let some className ← isClass? v.type | unreachable!
|
2022-05-19 22:36:21 +00:00
|
|
|
if let some instAttr ← getDefaultInstance v.name className then
|
2022-07-23 11:37:17 +00:00
|
|
|
info := { info with attrs := info.attrs.push instAttr }
|
2022-07-23 13:40:08 +00:00
|
|
|
let typeNames ← getInstanceTypes v.type
|
2022-11-20 10:47:53 +00:00
|
|
|
return {
|
2022-07-23 11:37:17 +00:00
|
|
|
toDefinitionInfo := info,
|
2022-07-23 13:40:08 +00:00
|
|
|
className,
|
|
|
|
typeNames
|
2022-07-23 11:37:17 +00:00
|
|
|
}
|
2022-05-19 22:36:21 +00:00
|
|
|
|
|
|
|
end DocGen4.Process
|