diff --git a/src/core/IronPython.StdLib/lib/test/test_grammar.py b/src/core/IronPython.StdLib/lib/test/test_grammar.py index e89748067..ac8d85a3c 100644 --- a/src/core/IronPython.StdLib/lib/test/test_grammar.py +++ b/src/core/IronPython.StdLib/lib/test/test_grammar.py @@ -1474,13 +1474,12 @@ async def foo(): pass async with manager() as (x, y): pass - # ironpython: todo implement this - #async with manager(), manager(): - # pass - #async with manager() as x, manager() as y: - # pass - #async with manager() as x, manager(): - # pass + async with manager(), manager(): + pass + async with manager() as x, manager() as y: + pass + async with manager() as x, manager(): + pass raise Done with self.assertRaises(Done): diff --git a/src/core/IronPython/Compiler/Parser.cs b/src/core/IronPython/Compiler/Parser.cs index 5033b6cf3..f76f0e161 100644 --- a/src/core/IronPython/Compiler/Parser.cs +++ b/src/core/IronPython/Compiler/Parser.cs @@ -1417,7 +1417,7 @@ private WithStatement ParseWithStmt() { var withItem = ParseWithItem(); List items = null; while (MaybeEat(TokenKind.Comma)) { - if (items == null) { + if (items is null) { items = new List(); } @@ -1427,7 +1427,7 @@ private WithStatement ParseWithStmt() { var header = GetEnd(); Statement body = ParseSuite(); - if (items != null) { + if (items is not null) { for (int i = items.Count - 1; i >= 0; i--) { var curItem = items[i]; var innerWith = new WithStatement(curItem.ContextManager, curItem.Variable, body); @@ -1480,12 +1480,34 @@ private AsyncWithStatement ParseAsyncWithStmt(int asyncStart) { } Eat(TokenKind.KeywordWith); + var withItem = ParseWithItem(); + List items = null; + while (MaybeEat(TokenKind.Comma)) { + if (items is null) { + items = new List(); + } + + items.Add(ParseWithItem()); + } + + var header = GetEnd(); Statement body = ParseSuite(); + if (items is not null) { + for (int i = items.Count - 1; i >= 0; i--) { + var curItem = items[i]; + var innerWith = new AsyncWithStatement(curItem.ContextManager, curItem.Variable, body); + innerWith.HeaderIndex = header; + innerWith.SetLoc(_globalParent, withItem.Start, GetEnd()); + body = innerWith; + header = GetEnd(); + } + } + AsyncWithStatement ret = new AsyncWithStatement(withItem.ContextManager, withItem.Variable, body); ret.HeaderIndex = header; - ret.SetLoc(_globalParent, asyncStart, GetEnd()); + ret.SetLoc(_globalParent, withItem.Start, GetEnd()); return ret; }