Struct ReadEvalLoop

Source
pub struct ReadEvalLoop<'a, 'b> { /* private fields */ }
๐Ÿ‘ŽDeprecated: use the read_eval_loop function instead
Expand description

Read-eval-loop

A read-eval-loop uses a Lexer for reading and parsing input and Env for executing parsed commands. It creates a Parser from the lexer to parse command lines. The loop executes each command line before parsing the following command line. The loop continues until the parser reaches the end of input or encounters a syntax error, or the command execution results in a Break(Divert::...).

If the input source code contains no commands, the exit status is set to zero. Otherwise, the exit status reflects the result of the last executed command.

Pending traps are run and subshell statuses are updated between parsing input and running commands.

ยงExample

let mut env = Env::new_virtual();
let mut lexer = Lexer::with_code("case foo in (bar) ;; esac");
let result = ReadEvalLoop::new(&mut env, &mut lexer).run().await;
assert_eq!(result, Continue(()));
assert_eq!(env.exit_status, ExitStatus::SUCCESS);

Implementationsยง

Sourceยง

impl<'a, 'b> ReadEvalLoop<'a, 'b>

Source

pub fn new(env: &'a mut Env, lexer: &'a mut Lexer<'b>) -> Self

Creates a new read-eval-loop instance.

This constructor requires two parameters: an environment in which the loop runs and a lexer that reads input.

Source

pub fn set_verbose(&mut self, verbose: Option<Rc<Cell<State>>>)

๐Ÿ‘ŽDeprecated: use yash_env::input::Echo instead

Sets a shared option state to which the verbose option is reflected.

This function is meant to be used with a lexer with an FdReader input. You should set the same shared cell of an option state to the input function and the loop. Before reading each command line, the loop copies the value of env.options.get(Verbose) to the cell. The input function checks it to see if it needs to echo the line it reads to the standard error. That achieves the effect of the Verbose shell option.

let mut env = Env::new_virtual();
let mut input = Box::new(FdReader::new(Fd::STDIN, Clone::clone(&env.system)));
let verbose = Rc::new(Cell::new(State::Off));
input.set_echo(Some(Rc::clone(&verbose)));
let mut lexer = Lexer::new(input);
let mut rel = ReadEvalLoop::new(&mut env, &mut lexer);
rel.set_verbose(Some(Rc::clone(&verbose)));
let _ = rel.run().await;
ยงDeprecation

This function is deprecated in favor of the Echo input decorator.

Source

pub async fn run(self) -> Result

Runs the read-eval-loop.

Trait Implementationsยง

Sourceยง

impl<'a, 'b> Debug for ReadEvalLoop<'a, 'b>

Sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementationsยง

ยง

impl<'a, 'b> Freeze for ReadEvalLoop<'a, 'b>

ยง

impl<'a, 'b> !RefUnwindSafe for ReadEvalLoop<'a, 'b>

ยง

impl<'a, 'b> !Send for ReadEvalLoop<'a, 'b>

ยง

impl<'a, 'b> !Sync for ReadEvalLoop<'a, 'b>

ยง

impl<'a, 'b> Unpin for ReadEvalLoop<'a, 'b>

ยง

impl<'a, 'b> !UnwindSafe for ReadEvalLoop<'a, 'b>

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> IntoEither for T

Sourceยง

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Sourceยง

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.