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
|
|
|
|
|
|
|
|
namespace DocGen4.Process
|
|
|
|
open Lean Widget Meta
|
|
|
|
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
Stores information about a typed name.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
structure NameInfo where
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
The name that has this info attached.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
name : Name
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
The pretty printed type of this name.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
type : CodeWithInfos
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
The doc string of the name if it exists.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
doc : Option String
|
|
|
|
deriving Inhabited
|
|
|
|
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
An argument to a declaration, e.g. the `(x : Nat)` in `def foo (x : Nat) := x`.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
structure Arg where
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
The name of the argument.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
name : Name
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
The pretty printed type of the argument.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
type : CodeWithInfos
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
What kind of binder was used for the argument.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
binderInfo : BinderInfo
|
|
|
|
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
A base structure for information about a declaration.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
structure Info extends NameInfo where
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
The list of arguments to the declaration.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
args : Array Arg
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
In which lines the declaration was created.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
declarationRange : DeclarationRange
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
A list of (known) attributes that are attached to the declaration.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
attrs : Array String
|
2023-02-16 18:51:35 +00:00
|
|
|
/--
|
|
|
|
Whether this info item should be rendered
|
|
|
|
-/
|
|
|
|
render : Bool := true
|
2022-05-19 22:36:21 +00:00
|
|
|
deriving Inhabited
|
|
|
|
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
Information about an `axiom` declaration.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
structure AxiomInfo extends Info where
|
|
|
|
isUnsafe : Bool
|
|
|
|
deriving Inhabited
|
|
|
|
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
Information about a `theorem` declaration.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
structure TheoremInfo extends Info
|
|
|
|
deriving Inhabited
|
|
|
|
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
2022-06-19 14:41:59 +00:00
|
|
|
Information about an `opaque` declaration.
|
2022-05-20 07:23:33 +00:00
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
structure OpaqueInfo extends Info where
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
The pretty printed value of the declaration.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
value : CodeWithInfos
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
2022-06-19 14:41:59 +00:00
|
|
|
A value of partial is interpreted as this opaque being part of a partial def
|
2022-05-20 07:23:33 +00:00
|
|
|
since the actual definition for a partial def is hidden behind an inaccessible value.
|
|
|
|
-/
|
2022-07-23 11:37:17 +00:00
|
|
|
definitionSafety : DefinitionSafety
|
2022-05-19 22:36:21 +00:00
|
|
|
deriving Inhabited
|
|
|
|
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
Information about a `def` declaration, note that partial defs are handled by `OpaqueInfo`.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
structure DefinitionInfo extends Info where
|
|
|
|
isUnsafe : Bool
|
|
|
|
hints : ReducibilityHints
|
|
|
|
equations : Option (Array CodeWithInfos)
|
|
|
|
isNonComputable : Bool
|
|
|
|
deriving Inhabited
|
|
|
|
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
Information about an `instance` declaration.
|
|
|
|
-/
|
2022-07-22 12:48:36 +00:00
|
|
|
structure InstanceInfo extends DefinitionInfo where
|
2022-07-23 11:37:17 +00:00
|
|
|
className : Name
|
2022-07-23 13:40:08 +00:00
|
|
|
typeNames : Array Name
|
2022-07-22 12:48:36 +00:00
|
|
|
deriving Inhabited
|
2022-05-19 22:36:21 +00:00
|
|
|
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
Information about an `inductive` declaration
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
structure InductiveInfo extends Info where
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
List of all constructors of this inductive type.
|
|
|
|
-/
|
|
|
|
ctors : List NameInfo
|
2022-05-19 22:36:21 +00:00
|
|
|
isUnsafe : Bool
|
|
|
|
deriving Inhabited
|
|
|
|
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
Information about a `structure` declaration.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
structure StructureInfo extends Info where
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
Information about all the fields of the structure.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
fieldInfo : Array NameInfo
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
All the structures this one inherited from.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
parents : Array Name
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
The constructor of the structure.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
ctor : NameInfo
|
|
|
|
deriving Inhabited
|
|
|
|
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
Information about a `class` declaration.
|
|
|
|
-/
|
2022-07-22 12:48:36 +00:00
|
|
|
abbrev ClassInfo := StructureInfo
|
2022-05-19 22:36:21 +00:00
|
|
|
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
Information about a `class inductive` declaration.
|
|
|
|
-/
|
2022-07-22 12:48:36 +00:00
|
|
|
abbrev ClassInductiveInfo := InductiveInfo
|
2022-05-19 22:36:21 +00:00
|
|
|
|
2023-02-16 18:51:35 +00:00
|
|
|
|
|
|
|
/--
|
|
|
|
Information about a constructor of an inductive type
|
|
|
|
-/
|
|
|
|
abbrev ConstructorInfo := Info
|
|
|
|
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
A general type for informations about declarations.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
inductive DocInfo where
|
|
|
|
| axiomInfo (info : AxiomInfo) : DocInfo
|
|
|
|
| theoremInfo (info : TheoremInfo) : DocInfo
|
|
|
|
| opaqueInfo (info : OpaqueInfo) : DocInfo
|
|
|
|
| definitionInfo (info : DefinitionInfo) : DocInfo
|
|
|
|
| instanceInfo (info : InstanceInfo) : DocInfo
|
|
|
|
| inductiveInfo (info : InductiveInfo) : DocInfo
|
|
|
|
| structureInfo (info : StructureInfo) : DocInfo
|
|
|
|
| classInfo (info : ClassInfo) : DocInfo
|
|
|
|
| classInductiveInfo (info : ClassInductiveInfo) : DocInfo
|
2023-02-16 18:51:35 +00:00
|
|
|
| ctorInfo (info : ConstructorInfo) : DocInfo
|
2022-05-19 22:36:21 +00:00
|
|
|
deriving Inhabited
|
|
|
|
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
Turns an `Expr` into a pretty printed `CodeWithInfos`.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
def prettyPrintTerm (expr : Expr) : MetaM CodeWithInfos := do
|
2023-01-01 18:30:28 +00:00
|
|
|
let ⟨fmt, infos⟩ ← PrettyPrinter.ppExprWithInfos expr
|
2022-05-19 22:36:21 +00:00
|
|
|
let tt := TaggedText.prettyTagged fmt
|
|
|
|
let ctx := {
|
|
|
|
env := ← getEnv
|
|
|
|
mctx := ← getMCtx
|
|
|
|
options := ← getOptions
|
|
|
|
currNamespace := ← getCurrNamespace
|
|
|
|
openDecls := ← getOpenDecls
|
|
|
|
fileMap := default,
|
|
|
|
ngen := ← getNGen
|
|
|
|
}
|
2023-01-01 18:30:28 +00:00
|
|
|
return tagCodeInfos ctx infos tt
|
2022-05-19 22:36:21 +00:00
|
|
|
|
|
|
|
def isInstance (declName : Name) : MetaM Bool := do
|
2023-01-01 18:30:28 +00:00
|
|
|
return (instanceExtension.getState (← getEnv)).instanceNames.contains declName
|
2022-05-19 22:36:21 +00:00
|
|
|
|
|
|
|
end DocGen4.Process
|