Skip to content

Commit

Permalink
Expect for after async instead of bump (#10877)
Browse files Browse the repository at this point in the history
Co-authored-by: Micha Reiser <micha@reiser.io>
  • Loading branch information
dhruvmanila and MichaReiser committed Apr 17, 2024
1 parent dc4cddb commit ea18276
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(async)
(x async x in iter)
10 changes: 9 additions & 1 deletion crates/ruff_python_parser/src/parser/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1934,7 +1934,15 @@ impl<'src> Parser<'src> {
let start = self.node_start();

let is_async = self.eat(TokenKind::Async);
self.bump(TokenKind::For);

if is_async {
// test_err comprehension_missing_for_after_async
// (async)
// (x async x in iter)
self.expect(TokenKind::For);
} else {
self.bump(TokenKind::For);
};

let saved_context = self.set_ctx(ParserCtxFlags::FOR_TARGET);
let mut target = self.parse_expression_list(AllowStarredExpression::Yes);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/comprehension_missing_for_after_async.py
---
## AST

```
Module(
ModModule {
range: 0..28,
body: [
Expr(
StmtExpr {
range: 0..7,
value: Generator(
ExprGenerator {
range: 0..7,
elt: Name(
ExprName {
range: 1..1,
id: "",
ctx: Invalid,
},
),
generators: [
Comprehension {
range: 1..6,
target: Name(
ExprName {
range: 6..6,
id: "",
ctx: Store,
},
),
iter: Name(
ExprName {
range: 6..6,
id: "",
ctx: Invalid,
},
),
ifs: [],
is_async: true,
},
],
parenthesized: true,
},
),
},
),
Expr(
StmtExpr {
range: 8..27,
value: Generator(
ExprGenerator {
range: 8..27,
elt: Name(
ExprName {
range: 9..10,
id: "x",
ctx: Load,
},
),
generators: [
Comprehension {
range: 11..26,
target: Name(
ExprName {
range: 17..18,
id: "x",
ctx: Store,
},
),
iter: Name(
ExprName {
range: 22..26,
id: "iter",
ctx: Load,
},
),
ifs: [],
is_async: true,
},
],
parenthesized: true,
},
),
},
),
],
},
)
```
## Errors

|
1 | (async)
| ^^^^^ Syntax Error: Expected an expression
2 | (x async x in iter)
|


|
1 | (async)
| ^ Syntax Error: Expected 'for', found ')'
2 | (x async x in iter)
|


|
1 | (async)
2 | (x async x in iter)
| ^ Syntax Error: Expected 'for', found name
|

0 comments on commit ea18276

Please sign in to comment.