Skip to content

Commit

Permalink
change vivax comprehension syntax a bit (and fix more grammar issues)
Browse files Browse the repository at this point in the history
  • Loading branch information
thatbirdguythatuknownot committed May 8, 2024
1 parent 5252558 commit 7bb83a4
Show file tree
Hide file tree
Showing 2 changed files with 3,151 additions and 2,597 deletions.
25 changes: 20 additions & 5 deletions Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -1428,16 +1428,26 @@ for_if_clause[comprehension_ty]:
| invalid_for_target

for_if_prefix_clauses[asdl_comprehension_seq*]:
| a[asdl_comprehension_seq*]=for_if_prefix_clause+ { a }
| invalid_for_if_prefix_clauses
| a[asdl_comprehension_seq*]=for_if_prefix_clause+ '->' { a }

for_if_prefix_clause[comprehension_ty]:
| 'async' 'for' a=star_targets 'in' ~ b=star_expressions ':' c[asdl_expr_seq*]=('if' z=named_expression ':' { z })* {
| 'async' 'for' a=star_targets 'in' b=star_expressions ':' &('if' | 'for') c[asdl_expr_seq*]=if_prefix_clause* {
CHECK_VERSION(comprehension_ty, 6, "Async comprehensions are", _PyAST_comprehension(a, b, c, 1, p->arena)) }
| 'for' a=star_targets 'in' ~ b=star_expressions ':' c[asdl_expr_seq*]=('if' z=named_expression ':' { z })* {
| 'for' a=star_targets 'in' b=star_expressions ':' &('if' | 'for') c[asdl_expr_seq*]=if_prefix_clause* {
_PyAST_comprehension(a, b, c, 0, p->arena) }
| "where" a=star_targets '=' b=star_expressions ':' c[asdl_expr_seq*]=('if' z=named_expression ':' { z })* {
| "where" a=star_targets '=' b=star_expressions ':' &('if' | 'for') c[asdl_expr_seq*]=if_prefix_clause* {
_PyAST_comprehension(a, _PyAST_List(CHECK(asdl_expr_seq*, _PyPegen_singleton_seq(p, b)), Load, EXTRA), c, 0, p->arena) }
| invalid_for_target
| 'async' 'for' a=star_targets 'in' b=star_expressions &'->' {
CHECK_VERSION(comprehension_ty, 6, "Async comprehensions are", _PyAST_comprehension(a, b, NULL, 1, p->arena)) }
| 'for' a=star_targets 'in' b=star_expressions &'->' {
_PyAST_comprehension(a, b, NULL, 0, p->arena) }
| "where" a=star_targets '=' b=star_expressions &'->' {
_PyAST_comprehension(a, _PyAST_List(CHECK(asdl_expr_seq*, _PyPegen_singleton_seq(p, b)), Load, EXTRA), NULL, 0, p->arena) }

if_prefix_clause[expr_ty]:
| 'if' z=named_expression ':' &('for' | 'if') { z }
| 'if' z=named_expression &'->' { z }

listcomp[expr_ty]:
| '[' a=named_expression b=for_if_clauses ']' { _PyAST_ListComp(a, b, EXTRA) }
Expand Down Expand Up @@ -1790,6 +1800,11 @@ invalid_with_item:
invalid_for_target:
| 'async'? 'for' a=star_expressions {
RAISE_SYNTAX_ERROR_INVALID_TARGET(FOR_TARGETS, a) }
invalid_for_if_prefix_clauses:
| for_if_prefix_clause+ ['async'] 'for' star_targets 'in' star_expressions a=':' {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "expected '->'") }
| for_if_prefix_clause+ "where" star_targets '=' star_expressions a=':' {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "expected '->'") }

invalid_group:
| '(' a=starred_expression ')' {
Expand Down
Loading

0 comments on commit 7bb83a4

Please sign in to comment.