Skip to main content

Repl

Struct Repl 

Source
pub struct Repl { /* private fields */ }
Expand description

The Vernacular REPL.

Maintains a kernel context and executes commands against it.

Implementations§

Source§

impl Repl

Source

pub fn new() -> Self

Create a new REPL with the standard library loaded.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn surface(&self) -> &Surface

Get a reference to the surface environment — the notation and macros in scope.

Source

pub fn context(&self) -> &Context

Get a reference to the underlying context.

Source

pub fn context_mut(&mut self) -> &mut Context

Get a mutable reference to the underlying context.

Trait Implementations§

Source§

impl Default for Repl

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.