mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-08 05:35:22 +00:00
Implement review comments and improve parsing a bit.
This commit is contained in:
parent
9f7ef2050e
commit
7e9b3ddc1f
2 changed files with 41 additions and 36 deletions
|
@ -385,35 +385,47 @@ impl Compiler {
|
|||
}
|
||||
self.set_label(end_label);
|
||||
}
|
||||
With { items, body } => {
|
||||
let end_label = self.new_label();
|
||||
for item in items {
|
||||
self.compile_expression(&item.context_expr)?;
|
||||
self.emit(Instruction::SetupWith { end: end_label });
|
||||
match &item.optional_vars {
|
||||
Some(var) => {
|
||||
self.compile_store(var)?;
|
||||
}
|
||||
None => {
|
||||
self.emit(Instruction::Pop);
|
||||
With {
|
||||
is_async,
|
||||
items,
|
||||
body,
|
||||
} => {
|
||||
if *is_async {
|
||||
unimplemented!("async with");
|
||||
} else {
|
||||
let end_label = self.new_label();
|
||||
for item in items {
|
||||
self.compile_expression(&item.context_expr)?;
|
||||
self.emit(Instruction::SetupWith { end: end_label });
|
||||
match &item.optional_vars {
|
||||
Some(var) => {
|
||||
self.compile_store(var)?;
|
||||
}
|
||||
None => {
|
||||
self.emit(Instruction::Pop);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.compile_statements(body)?;
|
||||
for _ in 0..items.len() {
|
||||
self.emit(Instruction::CleanupWith { end: end_label });
|
||||
self.compile_statements(body)?;
|
||||
for _ in 0..items.len() {
|
||||
self.emit(Instruction::CleanupWith { end: end_label });
|
||||
}
|
||||
self.set_label(end_label);
|
||||
}
|
||||
self.set_label(end_label);
|
||||
}
|
||||
For {
|
||||
is_async,
|
||||
target,
|
||||
iter,
|
||||
body,
|
||||
orelse,
|
||||
} => self.compile_for(target, iter, body, orelse)?,
|
||||
AsyncFor { .. } => {
|
||||
unimplemented!("async for");
|
||||
} => {
|
||||
if *is_async {
|
||||
unimplemented!("async for");
|
||||
} else {
|
||||
self.compile_for(target, iter, body, orelse)?
|
||||
}
|
||||
}
|
||||
Raise { exception, cause } => match exception {
|
||||
Some(value) => {
|
||||
|
@ -439,14 +451,18 @@ impl Compiler {
|
|||
finalbody,
|
||||
} => self.compile_try_statement(body, handlers, orelse, finalbody)?,
|
||||
FunctionDef {
|
||||
is_async,
|
||||
name,
|
||||
args,
|
||||
body,
|
||||
decorator_list,
|
||||
returns,
|
||||
} => self.compile_function_def(name, args, body, decorator_list, returns)?,
|
||||
AsyncFunctionDef { .. } => {
|
||||
unimplemented!("async def");
|
||||
} => {
|
||||
if *is_async {
|
||||
unimplemented!("async def");
|
||||
} else {
|
||||
self.compile_function_def(name, args, body, decorator_list, returns)?
|
||||
}
|
||||
}
|
||||
ClassDef {
|
||||
name,
|
||||
|
|
|
@ -240,13 +240,7 @@ impl SymbolTableBuilder {
|
|||
args,
|
||||
decorator_list,
|
||||
returns,
|
||||
}
|
||||
| AsyncFunctionDef {
|
||||
name,
|
||||
body,
|
||||
args,
|
||||
decorator_list,
|
||||
returns,
|
||||
..
|
||||
} => {
|
||||
self.scan_expressions(decorator_list)?;
|
||||
self.register_name(name, SymbolRole::Assigned)?;
|
||||
|
@ -289,12 +283,7 @@ impl SymbolTableBuilder {
|
|||
iter,
|
||||
body,
|
||||
orelse,
|
||||
}
|
||||
| AsyncFor {
|
||||
target,
|
||||
iter,
|
||||
body,
|
||||
orelse,
|
||||
..
|
||||
} => {
|
||||
self.scan_expression(target)?;
|
||||
self.scan_expression(iter)?;
|
||||
|
@ -346,7 +335,7 @@ impl SymbolTableBuilder {
|
|||
self.scan_expression(target)?;
|
||||
self.scan_expression(value)?;
|
||||
}
|
||||
With { items, body } => {
|
||||
With { items, body, .. } => {
|
||||
for item in items {
|
||||
self.scan_expression(&item.context_expr)?;
|
||||
if let Some(expression) = &item.optional_vars {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue