pub struct Interpreter<A> { /* private fields */ }
Expand description
An shell-like REPL interpreter.
Implementations§
Source§impl<A: Actionable> Interpreter<A>
impl<A: Actionable> Interpreter<A>
Sourcepub fn interpret_script(&mut self, script: &str) -> Result<()>
pub fn interpret_script(&mut self, script: &str) -> Result<()>
Examples found in repository?
examples/parser.rs (line 99)
83 pub fn enter_main() -> Result<()> {
84 let args: Vec<String> = std::env::args().collect();
85
86 let action = Action::default();
87 // enter shell mode or subcommands mode
88 if args.len() > 1 {
89 let args = Self::parse();
90 args.verbose.setup_logger();
91
92 if let Some(script_file) = &args.script_file {
93 info!("Execute script file: {:?}", script_file);
94 Interpreter::new(action).interpret_script_file(script_file)?;
95 } else {
96 info!("Reading batch script from stdin ..");
97 let mut buffer = String::new();
98 std::io::stdin().read_to_string(&mut buffer)?;
99 Interpreter::new(action).interpret_script(&buffer)?;
100 }
101 } else {
102 Interpreter::new(action).with_prompt("gosh> ").run()?;
103 }
104
105 Ok(())
106 }
Sourcepub fn interpret_script_file(&mut self, script_file: &Path) -> Result<()>
pub fn interpret_script_file(&mut self, script_file: &Path) -> Result<()>
Examples found in repository?
examples/parser.rs (line 94)
83 pub fn enter_main() -> Result<()> {
84 let args: Vec<String> = std::env::args().collect();
85
86 let action = Action::default();
87 // enter shell mode or subcommands mode
88 if args.len() > 1 {
89 let args = Self::parse();
90 args.verbose.setup_logger();
91
92 if let Some(script_file) = &args.script_file {
93 info!("Execute script file: {:?}", script_file);
94 Interpreter::new(action).interpret_script_file(script_file)?;
95 } else {
96 info!("Reading batch script from stdin ..");
97 let mut buffer = String::new();
98 std::io::stdin().read_to_string(&mut buffer)?;
99 Interpreter::new(action).interpret_script(&buffer)?;
100 }
101 } else {
102 Interpreter::new(action).with_prompt("gosh> ").run()?;
103 }
104
105 Ok(())
106 }
Source§impl<A: Actionable> Interpreter<A>
impl<A: Actionable> Interpreter<A>
Sourcepub fn new(action: A) -> Self
pub fn new(action: A) -> Self
Examples found in repository?
examples/parser.rs (line 94)
83 pub fn enter_main() -> Result<()> {
84 let args: Vec<String> = std::env::args().collect();
85
86 let action = Action::default();
87 // enter shell mode or subcommands mode
88 if args.len() > 1 {
89 let args = Self::parse();
90 args.verbose.setup_logger();
91
92 if let Some(script_file) = &args.script_file {
93 info!("Execute script file: {:?}", script_file);
94 Interpreter::new(action).interpret_script_file(script_file)?;
95 } else {
96 info!("Reading batch script from stdin ..");
97 let mut buffer = String::new();
98 std::io::stdin().read_to_string(&mut buffer)?;
99 Interpreter::new(action).interpret_script(&buffer)?;
100 }
101 } else {
102 Interpreter::new(action).with_prompt("gosh> ").run()?;
103 }
104
105 Ok(())
106 }
Source§impl<A: Actionable> Interpreter<A>
impl<A: Actionable> Interpreter<A>
Sourcepub fn with_history_file<P: Into<PathBuf>>(self, path: P) -> Self
pub fn with_history_file<P: Into<PathBuf>>(self, path: P) -> Self
Set absolute path to history file for permanently storing command history.
Sourcepub fn with_prompt(self, s: &str) -> Self
pub fn with_prompt(self, s: &str) -> Self
Set prompting string for REPL.
Examples found in repository?
examples/parser.rs (line 102)
83 pub fn enter_main() -> Result<()> {
84 let args: Vec<String> = std::env::args().collect();
85
86 let action = Action::default();
87 // enter shell mode or subcommands mode
88 if args.len() > 1 {
89 let args = Self::parse();
90 args.verbose.setup_logger();
91
92 if let Some(script_file) = &args.script_file {
93 info!("Execute script file: {:?}", script_file);
94 Interpreter::new(action).interpret_script_file(script_file)?;
95 } else {
96 info!("Reading batch script from stdin ..");
97 let mut buffer = String::new();
98 std::io::stdin().read_to_string(&mut buffer)?;
99 Interpreter::new(action).interpret_script(&buffer)?;
100 }
101 } else {
102 Interpreter::new(action).with_prompt("gosh> ").run()?;
103 }
104
105 Ok(())
106 }
Sourcepub fn run(&mut self) -> Result<()>
pub fn run(&mut self) -> Result<()>
Entry point for REPL.
Examples found in repository?
examples/parser.rs (line 102)
83 pub fn enter_main() -> Result<()> {
84 let args: Vec<String> = std::env::args().collect();
85
86 let action = Action::default();
87 // enter shell mode or subcommands mode
88 if args.len() > 1 {
89 let args = Self::parse();
90 args.verbose.setup_logger();
91
92 if let Some(script_file) = &args.script_file {
93 info!("Execute script file: {:?}", script_file);
94 Interpreter::new(action).interpret_script_file(script_file)?;
95 } else {
96 info!("Reading batch script from stdin ..");
97 let mut buffer = String::new();
98 std::io::stdin().read_to_string(&mut buffer)?;
99 Interpreter::new(action).interpret_script(&buffer)?;
100 }
101 } else {
102 Interpreter::new(action).with_prompt("gosh> ").run()?;
103 }
104
105 Ok(())
106 }
Auto Trait Implementations§
impl<A> Freeze for Interpreter<A>where
A: Freeze,
impl<A> RefUnwindSafe for Interpreter<A>where
A: RefUnwindSafe,
impl<A> Send for Interpreter<A>where
A: Send,
impl<A> Sync for Interpreter<A>where
A: Sync,
impl<A> Unpin for Interpreter<A>where
A: Unpin,
impl<A> UnwindSafe for Interpreter<A>where
A: UnwindSafe,
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
Mutably borrows from an owned value. Read more
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>
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 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>
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