impl std::str::FromStr for compile::Mode

This commit is contained in:
coolreader18 2019-08-11 22:15:07 -05:00
parent 11f4dc24dc
commit 240c3c417c

View file

@ -109,6 +109,35 @@ pub enum Mode {
Single,
}
impl std::str::FromStr for Mode {
type Err = ModeParseError;
fn from_str(s: &str) -> Result<Self, ModeParseError> {
match s {
"exec" => Ok(Mode::Exec),
"eval" => Ok(Mode::Eval),
"single" => Ok(Mode::Single),
_ => Err(ModeParseError { _priv: () }),
}
}
}
#[derive(Debug)]
pub struct ModeParseError {
_priv: (),
}
impl std::fmt::Display for ModeParseError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, r#"mode should be "exec", "eval", or "single""#)
}
}
#[derive(Clone, Copy)]
enum EvalContext {
Statement,
Expression,
}
pub(crate) type Label = usize;
impl<O> Default for Compiler<O>