Struct gosh_repl::Interpreter
source · 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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
pub fn enter_main() -> Result<()> {
let args: Vec<String> = std::env::args().collect();
let action = Action::default();
// enter shell mode or subcommands mode
if args.len() > 1 {
let args = Self::parse();
args.verbose.setup_logger();
if let Some(script_file) = &args.script_file {
info!("Execute script file: {:?}", script_file);
Interpreter::new(action).interpret_script_file(script_file)?;
} else {
info!("Reading batch script from stdin ..");
let mut buffer = String::new();
std::io::stdin().read_to_string(&mut buffer)?;
Interpreter::new(action).interpret_script(&buffer)?;
}
} else {
Interpreter::new(action).with_prompt("gosh> ").run()?;
}
Ok(())
}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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
pub fn enter_main() -> Result<()> {
let args: Vec<String> = std::env::args().collect();
let action = Action::default();
// enter shell mode or subcommands mode
if args.len() > 1 {
let args = Self::parse();
args.verbose.setup_logger();
if let Some(script_file) = &args.script_file {
info!("Execute script file: {:?}", script_file);
Interpreter::new(action).interpret_script_file(script_file)?;
} else {
info!("Reading batch script from stdin ..");
let mut buffer = String::new();
std::io::stdin().read_to_string(&mut buffer)?;
Interpreter::new(action).interpret_script(&buffer)?;
}
} else {
Interpreter::new(action).with_prompt("gosh> ").run()?;
}
Ok(())
}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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
pub fn enter_main() -> Result<()> {
let args: Vec<String> = std::env::args().collect();
let action = Action::default();
// enter shell mode or subcommands mode
if args.len() > 1 {
let args = Self::parse();
args.verbose.setup_logger();
if let Some(script_file) = &args.script_file {
info!("Execute script file: {:?}", script_file);
Interpreter::new(action).interpret_script_file(script_file)?;
} else {
info!("Reading batch script from stdin ..");
let mut buffer = String::new();
std::io::stdin().read_to_string(&mut buffer)?;
Interpreter::new(action).interpret_script(&buffer)?;
}
} else {
Interpreter::new(action).with_prompt("gosh> ").run()?;
}
Ok(())
}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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
pub fn enter_main() -> Result<()> {
let args: Vec<String> = std::env::args().collect();
let action = Action::default();
// enter shell mode or subcommands mode
if args.len() > 1 {
let args = Self::parse();
args.verbose.setup_logger();
if let Some(script_file) = &args.script_file {
info!("Execute script file: {:?}", script_file);
Interpreter::new(action).interpret_script_file(script_file)?;
} else {
info!("Reading batch script from stdin ..");
let mut buffer = String::new();
std::io::stdin().read_to_string(&mut buffer)?;
Interpreter::new(action).interpret_script(&buffer)?;
}
} else {
Interpreter::new(action).with_prompt("gosh> ").run()?;
}
Ok(())
}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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
pub fn enter_main() -> Result<()> {
let args: Vec<String> = std::env::args().collect();
let action = Action::default();
// enter shell mode or subcommands mode
if args.len() > 1 {
let args = Self::parse();
args.verbose.setup_logger();
if let Some(script_file) = &args.script_file {
info!("Execute script file: {:?}", script_file);
Interpreter::new(action).interpret_script_file(script_file)?;
} else {
info!("Reading batch script from stdin ..");
let mut buffer = String::new();
std::io::stdin().read_to_string(&mut buffer)?;
Interpreter::new(action).interpret_script(&buffer)?;
}
} else {
Interpreter::new(action).with_prompt("gosh> ").run()?;
}
Ok(())
}Auto Trait Implementations§
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