@@ -1980,13 +1980,9 @@ private Expression FinishUnaryNegate() {
19801980 return new UnaryExpression ( PythonOperator . Negate , ParseFactor ( ) ) ;
19811981 }
19821982
1983- // power: ['await'] atom trailer* ['**' factor]
1983+ // power: atom_expr ['**' factor]
19841984 private Expression ParsePower ( ) {
1985- if ( MaybeEat ( TokenKind . KeywordAwait ) ) {
1986- return ParseAwaitExpression ( ) ;
1987- }
1988- Expression ret = ParseAtom ( ) ;
1989- ret = AddTrailers ( ret ) ;
1985+ Expression ret = ParseAtomExpr ( ) ;
19901986 if ( MaybeEat ( TokenKind . Power ) ) {
19911987 var start = ret . StartIndex ;
19921988 ret = new BinaryExpression ( PythonOperator . Power , ret , ParseFactor ( ) ) ;
@@ -1995,25 +1991,27 @@ private Expression ParsePower() {
19951991 return ret ;
19961992 }
19971993
1998- // await_expr: 'await' unary_expr (essentially power level)
1999- private Expression ParseAwaitExpression ( ) {
2000- FunctionDefinition current = CurrentFunction ;
2001- if ( current == null || ! current . IsAsync ) {
2002- ReportSyntaxError ( "'await' outside async function" ) ;
1994+ // atom_expr: ['await'] atom trailer*
1995+ private Expression ParseAtomExpr ( ) {
1996+ var isAsync = MaybeEat ( TokenKind . KeywordAwait ) ;
1997+ if ( isAsync ) {
1998+ FunctionDefinition current = CurrentFunction ;
1999+ if ( current is null || ! current . IsAsync ) {
2000+ ReportSyntaxError ( "'await' outside async function" ) ;
2001+ }
2002+ if ( current is not null ) {
2003+ current . IsGenerator = true ;
2004+ current . GeneratorStop = GeneratorStop ;
2005+ }
20032006 }
20042007
2005- if ( current != null ) {
2006- current . IsGenerator = true ;
2007- current . GeneratorStop = GeneratorStop ;
2008+ Expression ret = ParseAtom ( ) ;
2009+ ret = AddTrailers ( ret ) ;
2010+ if ( isAsync ) {
2011+ var start = ret . StartIndex ;
2012+ ret = new AwaitExpression ( ret ) ;
2013+ ret . SetLoc ( _globalParent , start , GetEnd ( ) ) ;
20082014 }
2009-
2010- var start = GetStart ( ) ;
2011-
2012- // Parse the awaitable expression at the unary level
2013- Expression expr = ParsePower ( ) ;
2014-
2015- var ret = new AwaitExpression ( expr ) ;
2016- ret . SetLoc ( _globalParent , start , GetEnd ( ) ) ;
20172015 return ret ;
20182016 }
20192017
0 commit comments