pub struct ReadEvalLoop<'a, 'b> { /* private fields */ }
read_eval_loop
function insteadExpand 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>
impl<'a, 'b> ReadEvalLoop<'a, 'b>
Sourcepub fn new(env: &'a mut Env, lexer: &'a mut Lexer<'b>) -> Self
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.
Sourcepub fn set_verbose(&mut self, verbose: Option<Rc<Cell<State>>>)
๐Deprecated: use yash_env::input::Echo instead
pub fn set_verbose(&mut self, verbose: Option<Rc<Cell<State>>>)
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.
Trait Implementationsยง
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> 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
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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