mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-16 17:45:24 +00:00
replace try_parse!() macro to closure
This commit is contained in:
parent
fa6c66272e
commit
c476c276ab
1 changed files with 3 additions and 10 deletions
|
@ -99,21 +99,14 @@ pub fn compile_symtable(
|
||||||
mode: compile::Mode,
|
mode: compile::Mode,
|
||||||
source_path: &str,
|
source_path: &str,
|
||||||
) -> Result<symboltable::SymbolTable, CompileError> {
|
) -> Result<symboltable::SymbolTable, CompileError> {
|
||||||
macro_rules! try_parse {
|
let parse_err = |e| CompileError::from_parse(e, source, source_path.to_owned());
|
||||||
($x:expr) => {
|
|
||||||
match $x {
|
|
||||||
Ok(x) => x,
|
|
||||||
Err(e) => return Err(CompileError::from_parse(e, source, source_path.to_owned())),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
let res = match mode {
|
let res = match mode {
|
||||||
compile::Mode::Exec | compile::Mode::Single | compile::Mode::BlockExpr => {
|
compile::Mode::Exec | compile::Mode::Single | compile::Mode::BlockExpr => {
|
||||||
let ast = try_parse!(parser::parse_program(source));
|
let ast = parser::parse_program(source).map_err(parse_err)?;
|
||||||
symboltable::make_symbol_table(&ast)
|
symboltable::make_symbol_table(&ast)
|
||||||
}
|
}
|
||||||
compile::Mode::Eval => {
|
compile::Mode::Eval => {
|
||||||
let expr = try_parse!(parser::parse_expression(source));
|
let expr = parser::parse_expression(source).map_err(parse_err)?;
|
||||||
symboltable::make_symbol_table_expr(&expr)
|
symboltable::make_symbol_table_expr(&expr)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue