mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-16 09:35:19 +00:00
parser::Mode from compile::Mode
This commit is contained in:
parent
122382cb53
commit
8d39d5362b
2 changed files with 12 additions and 6 deletions
|
@ -17,6 +17,17 @@ impl Mode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<rustpython_compiler_core::Mode> for Mode {
|
||||||
|
fn from(mode: rustpython_compiler_core::Mode) -> Self {
|
||||||
|
use rustpython_compiler_core::Mode as CompileMode;
|
||||||
|
match mode {
|
||||||
|
CompileMode::Exec => Self::Module,
|
||||||
|
CompileMode::Eval => Self::Expression,
|
||||||
|
CompileMode::Single | CompileMode::BlockExpr => Self::Interactive,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl std::str::FromStr for Mode {
|
impl std::str::FromStr for Mode {
|
||||||
type Err = ModeParseError;
|
type Err = ModeParseError;
|
||||||
fn from_str(s: &str) -> Result<Self, ModeParseError> {
|
fn from_str(s: &str) -> Result<Self, ModeParseError> {
|
||||||
|
|
|
@ -31,12 +31,7 @@ pub fn compile(
|
||||||
source_path: String,
|
source_path: String,
|
||||||
opts: compile::CompileOpts,
|
opts: compile::CompileOpts,
|
||||||
) -> Result<CodeObject, CompileError> {
|
) -> Result<CodeObject, CompileError> {
|
||||||
let parser_mode = match mode {
|
let mut ast = match parser::parse(source, mode.into(), &source_path) {
|
||||||
compile::Mode::Exec => parser::Mode::Module,
|
|
||||||
compile::Mode::Eval => parser::Mode::Expression,
|
|
||||||
compile::Mode::Single | compile::Mode::BlockExpr => parser::Mode::Interactive,
|
|
||||||
};
|
|
||||||
let mut ast = match parser::parse(source, parser_mode, &source_path) {
|
|
||||||
Ok(x) => x,
|
Ok(x) => x,
|
||||||
Err(e) => return Err(error_from_parse(e, source)),
|
Err(e) => return Err(error_from_parse(e, source)),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue