A Scope
records the part of the CommandElabM
state that respects scoping,
such as the data for universe
, open
, and variable
declarations, the current namespace,
and currently enabled options.
The CommandElabM
state contains a stack of scopes, and only the top Scope
on the stack is read from or modified. There is always at least one Scope
on the stack,
even outside any section
or namespace
, and each new pushed Scope
starts as a modified copy of the previous top scope.
- header : String
The component of the
namespace
orsection
that this scope is associated to. For example,section a.b.c
andnamespace a.b.c
each create three scopes with headers nameda
,b
, andc
. This is used for checking theend
command. The "base scope" has""
as its header. - opts : Lean.Options
The current state of all set options at this point in the scope. Note that this is the full current set of options and does not simply contain the options set while this scope has been active.
- currNamespace : Lake.Name
The current namespace. The top-level namespace is represented by
Name.anonymous
. - openDecls : List Lean.OpenDecl
All currently
open
ed namespaces and names. The current list of names for universe level variables to use for new declarations. This is managed by the
universe
command.- varDecls : Array (Lean.TSyntax `Lean.Parser.Term.bracketedBinder)
The current list of binders to use for new declarations. This is managed by the
variable
command. Each binder is represented inSyntax
form, and it is re-elaborated within each command that uses this information.This is also used by commands, such as
#check
, to create an initial local context, even if they do not work with binders per se. Globally unique internal identifiers for the
varDecls
. There is one identifier per variable introduced by the binders (recall that a binder such as(a b c : Ty)
can produce more than one variable), and each identifier is the user-provided variable name with a macro scope. This is used byTermElabM
inLean.Elab.Term.Context
to help with processing macros that capture these variables.include
d section variable names (fromvarUIds
)omit
ted section variable names (fromvarUIds
)- isNoncomputable : Bool
If true (default: false), all declarations that fail to compile automatically receive the
noncomputable
modifier. A scope with this flag set is created bynoncomputable section
.Recall that a new scope inherits all values from its parent scope, so all sections and namespaces nested within a
noncomputable
section also have this flag set.
Instances For
Equations
- One or more equations did not get rendered due to their size.
- env : Lean.Environment
- messages : Lean.MessageLog
- scopes : List Lean.Elab.Command.Scope
- nextMacroScope : Nat
- maxRecDepth : Nat
- ngen : Lean.NameGenerator
- infoState : Lean.Elab.InfoState
- traceState : Lean.TraceState
Instances For
- fileName : String
- fileMap : Lean.FileMap
- currRecDepth : Nat
- cmdPos : String.Pos
- macroStack : Lean.Elab.MacroStack
- currMacroScope : Lean.MacroScope
- ref : Lean.Syntax
- tacticCache? : Option (IO.Ref Lean.Elab.Tactic.Cache)
Snapshot for incremental reuse and reporting of command elaboration. Currently only used for (mutual) defs and contained tactics, in which case the
DynamicSnapshot
is aHeadersParsedSnapshot
.Definitely resolved in
Language.Lean.process.doElab
.Invariant: if the bundle's
old?
is set, the context and state at the beginning of current and old elaboration are identical.- cancelTk? : Option IO.CancelToken
Cancellation token forwarded to
Core.cancelTk?
. - suppressElabErrors : Bool
If set (when
showPartialSyntaxErrors
is not set and parsing failed), suppresses most elaboration errors; see alsologMessage
below.
Instances For
Equations
Instances For
Instances For
Instances For
- name : Lake.Name
Instances For
Equations
- Lean.Elab.Command.instMonadCommandElabM = Monad.mk
Like Core.tryCatchRuntimeEx
; runtime errors are generally used to abort term elaboration, so we do
want to catch and process them at the command level.
Equations
- Lean.Elab.Command.tryCatch x h = tryCatch x fun (ex : Lean.Exception) => if ex.isInterrupt = true then throw ex else h ex
Instances For
Equations
- Lean.Elab.Command.instMonadExceptOfExceptionCommandElabM = { throw := fun {α : Type} => throw, tryCatch := fun {α : Type} => Lean.Elab.Command.tryCatch }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.addLinter l = do let ls ← ST.Ref.get Lean.Elab.Command.lintersRef ST.Ref.set Lean.Elab.Command.lintersRef (ls.push l)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Elab.Command.instMonadOptionsCommandElabM = { getOptions := do let __do_lift ← get pure __do_lift.scopes.head!.opts }
Equations
- Lean.Elab.Command.getRef = do let __do_lift ← read pure __do_lift.ref
Instances For
Equations
- Lean.Elab.Command.instAddMessageContextCommandElabM = { addMessageContext := Lean.addMessageContextPartial }
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Elab.Command.liftCoreM x = do let __do_lift ← Lean.Elab.Command.runCore (observing x) ofExcept __do_lift
Instances For
Equations
- Lean.Elab.Command.liftIO x = do let ctx ← read liftM (IO.toEIO (fun (ex : IO.Error) => Lean.Exception.error ctx.ref ((Lean.MessageData.ofFormat ∘ Lean.format) ex.toString)) x)
Instances For
Equations
- Lean.Elab.Command.instMonadLiftTIOCommandElabM = { monadLift := fun {α : Type} => Lean.Elab.Command.liftIO }
Return the current scope.
Equations
- Lean.Elab.Command.getScope = do let __do_lift ← get pure __do_lift.scopes.head!
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Elab.Command.getCurrMacroScope = do let __do_lift ← read pure __do_lift.currMacroScope
Instances For
Equations
- Lean.Elab.Command.getMainModule = do let __do_lift ← Lean.getEnv pure __do_lift.mainModule
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Disables incremental command reuse and reporting for act
if cond
is true by setting
Context.snap?
to none
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Elaborate x
with stx
on the macro stack
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Snapshot after macro expansion of a command.
- desc : String
- diagnostics : Lean.Language.Snapshot.Diagnostics
- infoTree? : Option Lean.Elab.InfoTree
- isFatal : Bool
- macroDecl : Lake.Name
The declaration name of the macro.
- newStx : Lean.Syntax
The expanded syntax tree.
- newNextMacroScope : Nat
State.nextMacroScope
after expansion. - hasTraces : Bool
Whether any traces were present after expansion.
Follow-up elaboration snapshots, one per command if
newStx
is a sequence of commands.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Option for showing elaboration errors from partial syntax errors.
elabCommand
wrapper that should be used for the initial invocation, not for recursive calls after
macro expansion etc.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Adapt a syntax transformation to a regular, command-producing elaborator.
Equations
- Lean.Elab.Command.adaptExpander exp stx = do let stx' ← exp stx Lean.Elab.Command.withMacroExpansion stx stx' (Lean.Elab.Command.elabCommand stx')
Instances For
Return identifier names in the given bracketed binder.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Lift the TermElabM
monadic action x
into a CommandElabM
monadic action.
Note that x
is executed with an empty message log. Thus, x
cannot modify/view messages produced by
previous commands.
If you need to access the free variables corresponding to the ones declared using the variable
command,
consider using runTermElabM
.
Recall that TermElabM
actions can automatically lift MetaM
and CoreM
actions.
Example:
import Lean
open Lean Elab Command Meta
def printExpr (e : Expr) : MetaM Unit := do
IO.println s!"{← ppExpr e} : {← ppExpr (← inferType e)}"
#eval
liftTermElabM do
printExpr (mkConst ``Nat)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Execute the monadic action elabFn xs
as a CommandElabM
monadic action, where xs
are free variables
corresponding to all active scoped variables declared using the variable
command.
This method is similar to liftTermElabM
, but it elaborates all scoped variables declared using the variable
command.
Example:
import Lean
open Lean Elab Command Meta
variable {α : Type u} {f : α → α}
variable (n : Nat)
#eval
runTermElabM fun xs => do
for x in xs do
IO.println s!"{← ppExpr x} : {← ppExpr (← inferType x)}"
Equations
- One or more equations did not get rendered due to their size.
Instances For
Catches and logs exceptions occurring in x
. Unlike try catch
in CommandElabM
, this function
catches interrupt exceptions as well and thus is intended for use at the top level of elaboration.
Interrupt and abort exceptions are caught but not logged.
Equations
- Lean.Elab.Command.withLoggingExceptions x ctx ref = (Lean.Elab.withLogging x ctx ref).catchExceptions fun (x : Lean.Exception) => pure ()
Instances For
Return the stack of all currently active scopes: the base scope always comes last; new scopes are prepended in the front. In particular, the current scope is always the first element.
Equations
- Lean.Elab.Command.getScopes = do let __do_lift ← get pure __do_lift.scopes
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Elab.Command.getLevelNames = do let __do_lift ← Lean.Elab.Command.getScope pure __do_lift.levelNames
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Lifts an action in CommandElabM
into CoreM
, updating the traces and the environment.
Commands that modify the processing of subsequent commands,
such as open
and namespace
commands,
only have an effect for the remainder of the CommandElabM
computation passed here,
and do not affect subsequent commands.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given a command elaborator cmd
, returns a new command elaborator that
first evaluates any local set_option ... in ...
clauses and then invokes cmd
on what remains.