Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Github issue 855 - fail to parse with statement #861

Merged
merged 2 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion native/libcst/src/parser/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ parser! {
}

rule with_item() -> WithItem<'input, 'a>
= e:expression() a:lit("as") t:star_target() &(lit(",") / lit(":")) {
= e:expression() a:lit("as") t:star_target() &(lit(",") / lit(":") / rpar()) {
make_with_item(e, Some(a), Some(t))
}
/ e:expression() {
Expand Down
27 changes: 24 additions & 3 deletions native/libcst/tests/fixtures/with_wickedness.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
# with_wickedness

with foo : ...
with foo :
pass

with foo, bar as bar:
pass

with (foo, bar as bar):
pass

with (foo, bar as bar,):
pass

async def f():
async with foo as bar:
async with foo:

with bar:
pass

async with foo(1+1) as bar , 1 as (a, b, ) , 2 as [a, b] , 3 as a[b] :
async with foo :
pass

async with foo, bar as bar:
pass

async with (foo, bar as bar):
pass

async with (foo, bar as bar,):
pass

async with foo(1+1) as bar , 1 as (a, b, ) , 2 as [a, b] , 3 as a[b] :
pass