Skip to content

Commit

Permalink
Update parser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed May 21, 2024
1 parent 54eff72 commit 9b33c47
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
async while test: ...
async x = 1
async async def foo(): ...
# TODO(dhruvmanila): Here, `match` is actually a Name token because
# of the soft keyword # transformer
async match test:
case _: ...
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# TODO(dhruvmanila): Here, `case` is a name token because of soft keyword transformer
match x:
case : ...
3 changes: 0 additions & 3 deletions crates/ruff_python_parser/src/parser/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2590,7 +2590,6 @@ impl<'src> Parser<'src> {
self.bump(TokenKind::Case);

// test_err match_stmt_missing_pattern
// # TODO(dhruvmanila): Here, `case` is a name token because of soft keyword transformer
// match x:
// case : ...
let pattern = self.parse_match_patterns();
Expand Down Expand Up @@ -2689,8 +2688,6 @@ impl<'src> Parser<'src> {
// async while test: ...
// async x = 1
// async async def foo(): ...
// # TODO(dhruvmanila): Here, `match` is actually a Name token because
// # of the soft keyword # transformer
// async match test:
// case _: ...
self.add_error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,13 @@ Module(
```
## Errors

|
1 | a: type X = int
| ^^^^ Syntax Error: Expected an identifier, but found a keyword 'type' that cannot be used here
2 | lambda: type X = int
|


|
1 | a: type X = int
| ^ Syntax Error: Simple statements must be separated by newlines or semicolons
2 | lambda: type X = int
|


|
1 | a: type X = int
2 | lambda: type X = int
| ^^^^ Syntax Error: Expected an identifier, but found a keyword 'type' that cannot be used here
|


|
1 | a: type X = int
2 | lambda: type X = int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ input_file: crates/ruff_python_parser/resources/inline/err/async_unexpected_toke
```
Module(
ModModule {
range: 0..220,
range: 0..116,
body: [
ClassDef(
StmtClassDef {
Expand Down Expand Up @@ -113,56 +113,41 @@ Module(
],
},
),
Expr(
StmtExpr {
range: 192..197,
value: Name(
Match(
StmtMatch {
range: 88..115,
subject: Name(
ExprName {
range: 192..197,
id: "match",
ctx: Load,
},
),
},
),
AnnAssign(
StmtAnnAssign {
range: 198..203,
target: Name(
ExprName {
range: 198..202,
range: 94..98,
id: "test",
ctx: Store,
},
),
annotation: Name(
ExprName {
range: 203..203,
id: "",
ctx: Invalid,
},
),
value: None,
simple: true,
},
),
AnnAssign(
StmtAnnAssign {
range: 213..219,
target: Name(
ExprName {
range: 213..214,
id: "_",
ctx: Store,
ctx: Load,
},
),
annotation: EllipsisLiteral(
ExprEllipsisLiteral {
range: 216..219,
cases: [
MatchCase {
range: 104..115,
pattern: MatchAs(
PatternMatchAs {
range: 109..110,
pattern: None,
name: None,
},
),
guard: None,
body: [
Expr(
StmtExpr {
range: 112..115,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 112..115,
},
),
},
),
],
},
),
value: None,
simple: true,
],
},
),
],
Expand Down Expand Up @@ -194,7 +179,7 @@ Module(
3 | async x = 1
| ^ Syntax Error: Expected 'def', 'with' or 'for' to follow 'async', found name
4 | async async def foo(): ...
5 | # TODO(dhruvmanila): Here, `match` is actually a Name token because
5 | async match test:
|


Expand All @@ -203,55 +188,15 @@ Module(
3 | async x = 1
4 | async async def foo(): ...
| ^^^^^ Syntax Error: Expected 'def', 'with' or 'for' to follow 'async', found 'async'
5 | # TODO(dhruvmanila): Here, `match` is actually a Name token because
6 | # of the soft keyword # transformer
|


|
5 | # TODO(dhruvmanila): Here, `match` is actually a Name token because
6 | # of the soft keyword # transformer
7 | async match test:
| ^^^^^ Syntax Error: Expected 'def', 'with' or 'for' to follow 'async', found name
8 | case _: ...
|


|
5 | # TODO(dhruvmanila): Here, `match` is actually a Name token because
6 | # of the soft keyword # transformer
7 | async match test:
| ^^^^ Syntax Error: Simple statements must be separated by newlines or semicolons
8 | case _: ...
|


|
5 | # TODO(dhruvmanila): Here, `match` is actually a Name token because
6 | # of the soft keyword # transformer
7 | async match test:
| ^ Syntax Error: Expected an expression
8 | case _: ...
5 | async match test:
6 | case _: ...
|


|
6 | # of the soft keyword # transformer
7 | async match test:
8 | case _: ...
| ^^^^ Syntax Error: Unexpected indentation
|


|
6 | # of the soft keyword # transformer
7 | async match test:
8 | case _: ...
| ^^^^ Syntax Error: Expected a statement
|


|
7 | async match test:
8 | case _: ...
3 | async x = 1
4 | async async def foo(): ...
5 | async match test:
| ^^^^^ Syntax Error: Expected 'def', 'with' or 'for' to follow 'async', found 'match'
6 | case _: ...
|
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,48 @@ input_file: crates/ruff_python_parser/resources/inline/err/match_stmt_missing_pa
```
Module(
ModModule {
range: 0..110,
range: 0..24,
body: [
Match(
StmtMatch {
range: 86..99,
range: 0..23,
subject: Name(
ExprName {
range: 92..93,
range: 6..7,
id: "x",
ctx: Load,
},
),
cases: [],
},
),
AnnAssign(
StmtAnnAssign {
range: 99..109,
target: Name(
ExprName {
range: 99..103,
id: "case",
ctx: Store,
},
),
annotation: EllipsisLiteral(
ExprEllipsisLiteral {
range: 106..109,
cases: [
MatchCase {
range: 13..23,
pattern: MatchValue(
PatternMatchValue {
range: 17..17,
value: Name(
ExprName {
range: 17..17,
id: "",
ctx: Invalid,
},
),
},
),
guard: None,
body: [
Expr(
StmtExpr {
range: 20..23,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 20..23,
},
),
},
),
],
},
),
value: None,
simple: true,
],
},
),
],
Expand All @@ -48,14 +58,7 @@ Module(
## Errors

|
1 | # TODO(dhruvmanila): Here, `case` is a name token because of soft keyword transformer
2 | match x:
3 | case : ...
| ^^^^ Syntax Error: Expected `case` block
|


|
2 | match x:
3 | case : ...
1 | match x:
2 | case : ...
| ^ Syntax Error: Expected a pattern
|
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,39 @@ Module(
body: [
Match(
StmtMatch {
range: 0..10,
range: 0..22,
subject: Name(
ExprName {
range: 6..9,
id: "foo",
ctx: Load,
},
),
cases: [],
},
),
Expr(
StmtExpr {
range: 11..15,
value: Name(
ExprName {
range: 11..15,
id: "case",
ctx: Load,
},
),
},
),
AnnAssign(
StmtAnnAssign {
range: 16..22,
target: Name(
ExprName {
range: 16..17,
id: "_",
ctx: Store,
cases: [
MatchCase {
range: 11..22,
pattern: MatchAs(
PatternMatchAs {
range: 16..17,
pattern: None,
name: None,
},
),
guard: None,
body: [
Expr(
StmtExpr {
range: 19..22,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 19..22,
},
),
},
),
],
},
),
annotation: EllipsisLiteral(
ExprEllipsisLiteral {
range: 19..22,
},
),
value: None,
simple: true,
],
},
),
],
Expand All @@ -61,11 +54,10 @@ Module(

|
1 | match foo: case _: ...
| ^^^^ Syntax Error: Expected newline, found name
| ^^^^ Syntax Error: Expected newline, found 'case'
|


|
1 | match foo: case _: ...
| ^ Syntax Error: Simple statements must be separated by newlines or semicolons
|

0 comments on commit 9b33c47

Please sign in to comment.