Handle raw yield expressions as RHS for augmented/annotated assignments

This commit is contained in:
Batuhan Taskaya committed 2020-11-30 03:11:09 +03:00
1 parent 9676ddb627
commit 698ae764f1
1 file changed
+9 -5
+9 -5
View File
@@ -107,7 +107,7 @@ ExpressionStatement: ast::Statement = {
}
}
},
<location:@L> <target:TestOrStarExprList> <op:AugAssign> <rhs:TestList> => {
<location:@L> <target:TestOrStarExprList> <op:AugAssign> <rhs:TestListOrYieldExpr> => {
ast::Statement {
location,
node: ast::StatementType::AugAssign {
@@ -117,23 +117,27 @@ ExpressionStatement: ast::Statement = {
},
}
},
<location:@L> <target:Test> ":" <annotation:Test> <rhs:("=" Test)?> => {
<location:@L> <target:Test> ":" <annotation:Test> <rhs:AssignSuffix?> => {
ast::Statement {
location,
node: ast::StatementType::AnnAssign {
target: Box::new(target),
annotation: Box::new(annotation),
value: rhs.map(|e| e.1)
value: rhs
},
}
},
};
AssignSuffix: ast::Expression = {
"=" <e:TestList> => e,
"=" <e:YieldExpr> => e,
"=" <e:TestListOrYieldExpr> => e
};
TestListOrYieldExpr: ast::Expression = {
TestList,
YieldExpr
}
TestOrStarExprList: ast::Expression = {
<location:@L> <elements:OneOrMore<TestOrStarExpr>> <comma:","?> => {
if elements.len() == 1 && comma.is_none() {