bookshelf-doc/DocGen4/Process/Base.lean

199 lines
4.5 KiB
Plaintext
Raw Normal View History

/-
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.
-/
structure NameInfo where
2022-05-20 07:23:33 +00:00
/--
The name that has this info attached.
-/
name : Name
2022-05-20 07:23:33 +00:00
/--
The pretty printed type of this name.
-/
type : CodeWithInfos
2022-05-20 07:23:33 +00:00
/--
The doc string of the name if it exists.
-/
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`.
-/
structure Arg where
2022-05-20 07:23:33 +00:00
/--
The name of the argument. For auto generated argument names like `[Monad α]`
this is none
2022-05-20 07:23:33 +00:00
-/
name : Option Name
2022-05-20 07:23:33 +00:00
/--
The pretty printed type of the argument.
-/
type : CodeWithInfos
2022-05-20 07:23:33 +00:00
/--
What kind of binder was used for the argument.
-/
binderInfo : BinderInfo
2022-05-20 07:23:33 +00:00
/--
A base structure for information about a declaration.
-/
structure Info extends NameInfo where
2022-05-20 07:23:33 +00:00
/--
The list of arguments to the declaration.
-/
args : Array Arg
2022-05-20 07:23:33 +00:00
/--
In which lines the declaration was created.
-/
declarationRange : DeclarationRange
2022-05-20 07:23:33 +00:00
/--
A list of (known) attributes that are attached to the declaration.
-/
attrs : Array String
2023-02-16 18:51:35 +00:00
/--
Whether this info item should be rendered
-/
render : Bool := true
deriving Inhabited
2022-05-20 07:23:33 +00:00
/--
Information about an `axiom` declaration.
-/
structure AxiomInfo extends Info where
isUnsafe : Bool
deriving Inhabited
2022-05-20 07:23:33 +00:00
/--
Information about a `theorem` declaration.
-/
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
-/
structure OpaqueInfo extends Info where
2022-05-20 07:23:33 +00:00
/--
The pretty printed value of the declaration.
-/
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
deriving Inhabited
2022-05-20 07:23:33 +00:00
/--
Information about a `def` declaration, note that partial defs are handled by `OpaqueInfo`.
-/
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.
-/
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
deriving Inhabited
2022-05-20 07:23:33 +00:00
/--
Information about an `inductive` declaration
-/
structure InductiveInfo extends Info where
2022-05-20 07:23:33 +00:00
/--
List of all constructors of this inductive type.
-/
ctors : List NameInfo
isUnsafe : Bool
deriving Inhabited
2022-05-20 07:23:33 +00:00
/--
Information about a `structure` declaration.
-/
structure StructureInfo extends Info where
2022-05-20 07:23:33 +00:00
/--
Information about all the fields of the structure.
-/
fieldInfo : Array NameInfo
2022-05-20 07:23:33 +00:00
/--
All the structures this one inherited from.
-/
parents : Array Name
2022-05-20 07:23:33 +00:00
/--
The constructor of the structure.
-/
ctor : NameInfo
deriving Inhabited
2022-05-20 07:23:33 +00:00
/--
Information about a `class` declaration.
-/
abbrev ClassInfo := StructureInfo
2022-05-20 07:23:33 +00:00
/--
Information about a `class inductive` declaration.
-/
abbrev ClassInductiveInfo := InductiveInfo
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.
-/
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
deriving Inhabited
2022-05-20 07:23:33 +00:00
/--
Turns an `Expr` into a pretty printed `CodeWithInfos`.
-/
def prettyPrintTerm (expr : Expr) : MetaM CodeWithInfos := do
let ⟨fmt, infos⟩ ← PrettyPrinter.ppExprWithInfos expr
let tt := TaggedText.prettyTagged fmt
let ctx := {
env := ← getEnv
mctx := ← getMCtx
options := ← getOptions
currNamespace := ← getCurrNamespace
openDecls := ← getOpenDecls
fileMap := default,
ngen := ← getNGen
}
return tagCodeInfos ctx infos tt
def isInstance (declName : Name) : MetaM Bool := do
return (instanceExtension.getState (← getEnv)).instanceNames.contains declName
end DocGen4.Process