Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions src/core/IronPython/Compiler/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1980,13 +1980,9 @@ private Expression FinishUnaryNegate() {
return new UnaryExpression(PythonOperator.Negate, ParseFactor());
}

// power: ['await'] atom trailer* ['**' factor]
// power: atom_expr ['**' factor]
private Expression ParsePower() {
if (MaybeEat(TokenKind.KeywordAwait)) {
return ParseAwaitExpression();
}
Expression ret = ParseAtom();
ret = AddTrailers(ret);
Expression ret = ParseAtomExpr();
if (MaybeEat(TokenKind.Power)) {
var start = ret.StartIndex;
ret = new BinaryExpression(PythonOperator.Power, ret, ParseFactor());
Expand All @@ -1995,25 +1991,27 @@ private Expression ParsePower() {
return ret;
}

// await_expr: 'await' unary_expr (essentially power level)
private Expression ParseAwaitExpression() {
FunctionDefinition current = CurrentFunction;
if (current == null || !current.IsAsync) {
ReportSyntaxError("'await' outside async function");
// atom_expr: ['await'] atom trailer*
private Expression ParseAtomExpr() {
var isAsync = MaybeEat(TokenKind.KeywordAwait);
if (isAsync) {
FunctionDefinition current = CurrentFunction;
if (current is null || !current.IsAsync) {
ReportSyntaxError("'await' outside async function");
}
if (current is not null) {
current.IsGenerator = true;
current.GeneratorStop = GeneratorStop;
}
}

if (current != null) {
current.IsGenerator = true;
current.GeneratorStop = GeneratorStop;
Expression ret = ParseAtom();
ret = AddTrailers(ret);
if (isAsync) {
var start = ret.StartIndex;
ret = new AwaitExpression(ret);
ret.SetLoc(_globalParent, start, GetEnd());
}

var start = GetStart();

// Parse the awaitable expression at the unary level
Expression expr = ParsePower();

var ret = new AwaitExpression(expr);
ret.SetLoc(_globalParent, start, GetEnd());
return ret;
}

Expand Down