Struct Interpreter

Source
pub struct Interpreter<A> { /* private fields */ }
Expand description

An shell-like REPL interpreter.

Implementations§

Source§

impl<A: Actionable> Interpreter<A>

Source

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        }
Source

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>

Source

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>

Source

pub fn with_history_file<P: Into<PathBuf>>(self, path: P) -> Self

Set absolute path to history file for permanently storing command history.

Source

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        }
Source

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.