Skip to content

Commit 698ae76

Browse files
committed
Handle raw yield expressions as RHS for augmented/annotated assignments
1 parent 9676ddb commit 698ae76

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

parser/src/python.lalrpop

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ ExpressionStatement: ast::Statement = {
107107
}
108108
}
109109
},
110-
<location:@L> <target:TestOrStarExprList> <op:AugAssign> <rhs:TestList> => {
110+
<location:@L> <target:TestOrStarExprList> <op:AugAssign> <rhs:TestListOrYieldExpr> => {
111111
ast::Statement {
112112
location,
113113
node: ast::StatementType::AugAssign {
@@ -117,23 +117,27 @@ ExpressionStatement: ast::Statement = {
117117
},
118118
}
119119
},
120-
<location:@L> <target:Test> ":" <annotation:Test> <rhs:("=" Test)?> => {
120+
<location:@L> <target:Test> ":" <annotation:Test> <rhs:AssignSuffix?> => {
121121
ast::Statement {
122122
location,
123123
node: ast::StatementType::AnnAssign {
124124
target: Box::new(target),
125125
annotation: Box::new(annotation),
126-
value: rhs.map(|e| e.1)
126+
value: rhs
127127
},
128128
}
129129
},
130130
};
131131

132132
AssignSuffix: ast::Expression = {
133-
"=" <e:TestList> => e,
134-
"=" <e:YieldExpr> => e,
133+
"=" <e:TestListOrYieldExpr> => e
135134
};
136135

136+
TestListOrYieldExpr: ast::Expression = {
137+
TestList,
138+
YieldExpr
139+
}
140+
137141
TestOrStarExprList: ast::Expression = {
138142
<location:@L> <elements:OneOrMore<TestOrStarExpr>> <comma:","?> => {
139143
if elements.len() == 1 && comma.is_none() {

0 commit comments

Comments
 (0)