mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-22 04:25:25 +00:00
rustpython-bytecode -> rustpython-compiler-core
This commit is contained in:
parent
d60ad9be23
commit
b3095c7451
11 changed files with 25 additions and 23 deletions
32
core/src/mode.rs
Normal file
32
core/src/mode.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
#[derive(Clone, Copy)]
|
||||
pub enum Mode {
|
||||
Exec,
|
||||
Eval,
|
||||
Single,
|
||||
BlockExpr,
|
||||
}
|
||||
|
||||
impl std::str::FromStr for Mode {
|
||||
type Err = ModeParseError;
|
||||
|
||||
// To support `builtins.compile()` `mode` argument
|
||||
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""#)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue