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
|
|
|
|
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
|
|
|
/--
|
|
|
|
Information about a `constant` declaration.
|
|
|
|
-/
|
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
|
|
|
/--
|
|
|
|
A value of partial is interpreted as this constant being part of a partial def
|
|
|
|
since the actual definition for a partial def is hidden behind an inaccessible value.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
unsafeInformation : DefinitionSafety
|
|
|
|
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-05-19 22:36:21 +00:00
|
|
|
abbrev InstanceInfo := DefinitionInfo
|
|
|
|
|
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-05-19 22:36:21 +00:00
|
|
|
structure ClassInfo extends StructureInfo where
|
|
|
|
instances : Array Name
|
|
|
|
deriving Inhabited
|
|
|
|
|
2022-05-20 07:23:33 +00:00
|
|
|
/--
|
|
|
|
Information about a `class inductive` declaration.
|
|
|
|
-/
|
2022-05-19 22:36:21 +00:00
|
|
|
structure ClassInductiveInfo extends InductiveInfo where
|
|
|
|
instances : Array Name
|
|
|
|
deriving Inhabited
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
let (fmt, infos) ← formatInfos expr
|
|
|
|
let tt := TaggedText.prettyTagged fmt
|
|
|
|
let ctx := {
|
|
|
|
env := ← getEnv
|
|
|
|
mctx := ← getMCtx
|
|
|
|
options := ← getOptions
|
|
|
|
currNamespace := ← getCurrNamespace
|
|
|
|
openDecls := ← getOpenDecls
|
|
|
|
fileMap := default,
|
|
|
|
ngen := ← getNGen
|
|
|
|
}
|
|
|
|
pure $ tagExprInfos ctx infos tt
|
|
|
|
|
|
|
|
def isInstance (declName : Name) : MetaM Bool := do
|
|
|
|
pure $ (instanceExtension.getState (←getEnv)).instanceNames.contains declName
|
|
|
|
|
|
|
|
end DocGen4.Process
|