mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-28 22:35:02 +00:00
Update the compiler to use the new asdl ast types
This commit is contained in:
parent
dd7560c494
commit
e494175cd2
1 changed files with 11 additions and 24 deletions
|
@ -75,29 +75,16 @@ pub fn compile(
|
||||||
source_path: String,
|
source_path: String,
|
||||||
opts: CompileOpts,
|
opts: CompileOpts,
|
||||||
) -> Result<CodeObject, CompileError> {
|
) -> Result<CodeObject, CompileError> {
|
||||||
macro_rules! try_parse {
|
let mode = match mode {
|
||||||
($x:expr) => {
|
compile::Mode::Exec => parser::Mode::Module,
|
||||||
match $x {
|
compile::Mode::Eval => parser::Mode::Expression,
|
||||||
|
compile::Mode::Single => parser::Mode::Interactive,
|
||||||
|
};
|
||||||
|
let ast = match parser::parse(source, mode) {
|
||||||
Ok(x) => x,
|
Ok(x) => x,
|
||||||
Err(e) => return Err(CompileError::from_parse(e, source, source_path)),
|
Err(e) => return Err(CompileError::from_parse(e, source, source_path)),
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
compile::compile_top(&ast, source_path, opts).map_err(|e| CompileError::from_compile(e, source))
|
||||||
let res = match mode {
|
|
||||||
compile::Mode::Exec => {
|
|
||||||
let ast = try_parse!(parser::parse_program(source));
|
|
||||||
compile::compile_program(ast, source_path, opts)
|
|
||||||
}
|
|
||||||
compile::Mode::Eval => {
|
|
||||||
let statement = try_parse!(parser::parse_statement(source));
|
|
||||||
compile::compile_statement_eval(statement, source_path, opts)
|
|
||||||
}
|
|
||||||
compile::Mode::Single => {
|
|
||||||
let ast = try_parse!(parser::parse_program(source));
|
|
||||||
compile::compile_program_single(ast, source_path, opts)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
res.map_err(|e| CompileError::from_compile(e, source))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compile_symtable(
|
pub fn compile_symtable(
|
||||||
|
@ -119,8 +106,8 @@ pub fn compile_symtable(
|
||||||
symboltable::make_symbol_table(&ast)
|
symboltable::make_symbol_table(&ast)
|
||||||
}
|
}
|
||||||
compile::Mode::Eval => {
|
compile::Mode::Eval => {
|
||||||
let statement = try_parse!(parser::parse_statement(source));
|
let expr = try_parse!(parser::parse_expression(source));
|
||||||
symboltable::statements_to_symbol_table(&statement)
|
symboltable::make_symbol_table_expr(&expr)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
res.map_err(|e| CompileError::from_symtable(e, source, source_path.to_owned()))
|
res.map_err(|e| CompileError::from_symtable(e, source, source_path.to_owned()))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue