pub struct Repl { /* private fields */ }Expand description
The Vernacular REPL.
Maintains a kernel context and executes commands against it.
Implementations§
Source§impl Repl
impl Repl
Sourcepub fn execute(&mut self, input: &str) -> Result<String, InterfaceError>
pub fn execute(&mut self, input: &str) -> Result<String, InterfaceError>
Execute a command string.
Returns the output string (for Check/Eval) or empty string (for Definition/Inductive).
Sourcepub fn execute_batch(
&mut self,
inputs: &[String],
) -> Vec<Result<String, InterfaceError>>
pub fn execute_batch( &mut self, inputs: &[String], ) -> Vec<Result<String, InterfaceError>>
Execute a batch of Vernacular commands, recovering mutual-inductive grouping.
execute registers each Inductive independently, so a forward
reference between two separately-declared inductives — Tree whose Node
constructor mentions Forest, declared next — fails: Forest is not yet in scope
when Tree’s constructor is universe-checked. True mutual inductives must be
registered together, through the trusted Context::add_mutual_inductives, which
runs whole-block positivity and a header-first universe check.
This entry point recovers that grouping from a flat statement sequence: a maximal
run of consecutive Inductive commands is split into strongly-connected components
of the “a constructor mentions sibling b” graph. A genuine cycle (Tree↔Forest)
is registered as one mutual block; an acyclic reference (Leafy → Bare) becomes
two singletons registered dependency-first (Bare, then Leafy) through the
ordinary single-inductive path. Every non-inductive command — and every inductive
with no forward reference — runs exactly as execute would, in source order, so a
batch without forward references is byte-identical to running the statements singly.
Sourcepub fn execute_document(
&mut self,
input: &str,
) -> Result<Vec<String>, InterfaceError>
pub fn execute_document( &mut self, input: &str, ) -> Result<Vec<String>, InterfaceError>
Execute a whole DOCUMENT: every command in it, in order, stopping at the first failure.
execute is a single-command door and refuses a prefix, which is what
stops a second ## Theorem block from being discarded in silence. This is the other half:
the door that actually reads a document. It is fail-loud and fail-EARLY — a block that does
not check aborts the run, so nothing after a refused theorem is registered and the caller
gets the error rather than a success that covered a smaller set of blocks than it was
handed. Mutual-inductive grouping is the same as Self::execute_batch’s.
It is also BALANCED: a document must leave the scope stack exactly as it found it. A
Namespace N. with no End N. would write every LATER command into N with nothing said,
and a document that closes a scope the caller opened moves the caller’s later declarations
somewhere nobody wrote. Lean does NOT refuse one — measured on lean 4.14.0, a file that ends inside namespace N compiles without a word, because a Lean MODULE’s scopes close at its end and the next file starts clean. A document here is not a module: it is handed to a live session that goes on executing commands after it, so an unclosed Namespace N. keys every later one into N and says nothing. The balance rule is therefore ours and deliberate, and the reason is the session rather than Lean.
A refused document has its namespace scope wound back to where the caller handed it over.
Sourcepub fn shadows(&self) -> Vec<(String, String)>
pub fn shadows(&self) -> Vec<(String, String)>
The names this session shadows, as (written name, kernel identity) pairs: a written name
in this table denotes the session’s own declaration at that identity, and the environment’s
declaration under the same name keeps its meaning.
Sourcepub fn shadow_snapshots(&self) -> usize
pub fn shadow_snapshots(&self) -> usize
How many commands this session has run under the shadowing snapshot — exactly the commands that redeclared a name the environment already held. The snapshot is what makes the retry possible and is not free: while it lives, a command’s first write to each table it touches copies the whole table. A command declaring only fresh names never takes one, and this count is how that is held.
Sourcepub fn surface(&self) -> &Surface
pub fn surface(&self) -> &Surface
Get a reference to the surface environment — the notation and macros in scope.
Sourcepub fn context_mut(&mut self) -> &mut Context
pub fn context_mut(&mut self) -> &mut Context
Get a mutable reference to the underlying context.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Repl
impl RefUnwindSafe for Repl
impl Send for Repl
impl Sync for Repl
impl Unpin for Repl
impl UnsafeUnpin for Repl
impl UnwindSafe for Repl
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.