mirror of
https://github.com/RustPython/Parser.git
synced 2025-09-22 01:52:31 +00:00
Address comments
Signed-off-by: harupy <hkawamura0130@gmail.com>
This commit is contained in:
parent
d6f9dd0763
commit
de2e88656e
1 changed files with 16 additions and 13 deletions
|
@ -361,10 +361,11 @@ IfStatement: ast::Stmt = {
|
||||||
// Determine last else:
|
// Determine last else:
|
||||||
let mut last = s3.map(|s| s.2).unwrap_or_default();
|
let mut last = s3.map(|s| s.2).unwrap_or_default();
|
||||||
let end_location = last
|
let end_location = last
|
||||||
.last()
|
.last()
|
||||||
.map(|last| last.end_location)
|
.or_else(|| s2.last().and_then(|last| last.4.last()))
|
||||||
.or_else(|| s2.last().map(|last| last.4.last().unwrap().end_location))
|
.or_else(|| body.last())
|
||||||
.unwrap_or_else(|| body.last().unwrap().end_location);
|
.unwrap()
|
||||||
|
.end_location;
|
||||||
// handle elif:
|
// handle elif:
|
||||||
for i in s2.into_iter().rev() {
|
for i in s2.into_iter().rev() {
|
||||||
let x = ast::Stmt {
|
let x = ast::Stmt {
|
||||||
|
@ -387,11 +388,12 @@ IfStatement: ast::Stmt = {
|
||||||
|
|
||||||
WhileStatement: ast::Stmt = {
|
WhileStatement: ast::Stmt = {
|
||||||
<location:@L> "while" <test:NamedExpressionTest> ":" <body:Suite> <s2:("else" ":" Suite)?> => {
|
<location:@L> "while" <test:NamedExpressionTest> ":" <body:Suite> <s2:("else" ":" Suite)?> => {
|
||||||
let end_location = s2
|
|
||||||
.as_ref()
|
|
||||||
.map(|s| s.2.last().unwrap().end_location)
|
|
||||||
.unwrap_or_else(|| body.last().unwrap().end_location);
|
|
||||||
let orelse = s2.map(|s| s.2).unwrap_or_default();
|
let orelse = s2.map(|s| s.2).unwrap_or_default();
|
||||||
|
let end_location = orelse
|
||||||
|
.last()
|
||||||
|
.or_else(|| body.last())
|
||||||
|
.unwrap()
|
||||||
|
.end_location;
|
||||||
ast::Stmt {
|
ast::Stmt {
|
||||||
custom: (),
|
custom: (),
|
||||||
location,
|
location,
|
||||||
|
@ -407,12 +409,13 @@ WhileStatement: ast::Stmt = {
|
||||||
|
|
||||||
ForStatement: ast::Stmt = {
|
ForStatement: ast::Stmt = {
|
||||||
<location:@L> <is_async:"async"?> "for" <target:ExpressionList> "in" <iter:TestList> ":" <body:Suite> <s2:("else" ":" Suite)?> => {
|
<location:@L> <is_async:"async"?> "for" <target:ExpressionList> "in" <iter:TestList> ":" <body:Suite> <s2:("else" ":" Suite)?> => {
|
||||||
let end_location = s2
|
|
||||||
.as_ref()
|
|
||||||
.map(|s| s.2.last().unwrap().end_location)
|
|
||||||
.unwrap_or_else(|| body.last().unwrap().end_location)
|
|
||||||
.unwrap();
|
|
||||||
let orelse = s2.map(|s| s.2).unwrap_or_default();
|
let orelse = s2.map(|s| s.2).unwrap_or_default();
|
||||||
|
let end_location = orelse
|
||||||
|
.last()
|
||||||
|
.or_else(|| body.last())
|
||||||
|
.unwrap()
|
||||||
|
.end_location
|
||||||
|
.unwrap();
|
||||||
let target = Box::new(set_context(target, ast::ExprContext::Store));
|
let target = Box::new(set_context(target, ast::ExprContext::Store));
|
||||||
let iter = Box::new(iter);
|
let iter = Box::new(iter);
|
||||||
let type_comment = None;
|
let type_comment = None;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue