mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-08 05:35:22 +00:00
impl std::str::FromStr for compile::Mode
This commit is contained in:
parent
11f4dc24dc
commit
240c3c417c
1 changed files with 29 additions and 0 deletions
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue