@@ -157,7 +157,7 @@ assignment[stmt_ty]:
157157 _PyAST_AnnAssign(CHECK(expr_ty, _PyPegen_set_expr_context(p, a, Store)), b, c, 1, EXTRA)
158158 ) }
159159 | a=('(' b=single_target ')' { b }
160- | single_subscript_attribute_target ) ':' b=expression c=['=' d=annotated_rhs { d }] {
160+ | attribute_or_subscript_target ) ':' b=expression c=['=' d=annotated_rhs { d }] {
161161 CHECK_VERSION(stmt_ty, 6, "Variable annotations syntax is", _PyAST_AnnAssign(a, b, c, 0, EXTRA)) }
162162 | a[asdl_expr_seq*]=(z=star_targets '=' { z })+ b=annotated_rhs !'=' tc=[TYPE_COMMENT] {
163163 _PyAST_Assign(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) }
@@ -740,16 +740,10 @@ star_expression[expr_ty] (memo):
740740
741741star_named_expressions[asdl_expr_seq*]: a[asdl_expr_seq*]=','.star_named_expression+ [','] { a }
742742
743- star_named_expressions_sequence[asdl_expr_seq*]: a[asdl_expr_seq*]=','.star_named_expression_sequence+ [','] { a }
744-
745743star_named_expression[expr_ty]:
746744 | '*' a=bitwise_or { _PyAST_Starred(a, Load, EXTRA) }
747745 | named_expression
748746
749- star_named_expression_sequence[expr_ty]:
750- | invalid_starred_expression_unpacking_sequence
751- | star_named_expression
752-
753747assignment_expression[expr_ty]:
754748 | a=NAME ':=' ~ b=expression {
755749 CHECK_VERSION(expr_ty, 8, "Assignment expressions are",
@@ -791,28 +785,16 @@ comparison[expr_ty]:
791785 | bitwise_or
792786
793787compare_op_bitwise_or_pair[CmpopExprPair*]:
794- | eq_bitwise_or
795- | noteq_bitwise_or
796- | lte_bitwise_or
797- | lt_bitwise_or
798- | gte_bitwise_or
799- | gt_bitwise_or
800- | notin_bitwise_or
801- | in_bitwise_or
802- | isnot_bitwise_or
803- | is_bitwise_or
804-
805- eq_bitwise_or[CmpopExprPair*]: '==' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Eq, a) }
806- noteq_bitwise_or[CmpopExprPair*]:
788+ | '==' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Eq, a) }
807789 | (tok='!=' { _PyPegen_check_barry_as_flufl(p, tok) ? NULL : tok}) a=bitwise_or {_PyPegen_cmpop_expr_pair(p, NotEq, a) }
808- lte_bitwise_or[CmpopExprPair*]: '<=' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, LtE, a) }
809- lt_bitwise_or[CmpopExprPair*]: '<' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Lt, a) }
810- gte_bitwise_or[CmpopExprPair*]: '>=' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, GtE, a) }
811- gt_bitwise_or[CmpopExprPair*]: '>' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Gt, a) }
812- notin_bitwise_or[CmpopExprPair*]: 'not' 'in' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, NotIn, a) }
813- in_bitwise_or[CmpopExprPair*]: 'in' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, In, a) }
814- isnot_bitwise_or[CmpopExprPair*]: 'is' 'not' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, IsNot, a) }
815- is_bitwise_or[CmpopExprPair*]: 'is' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Is, a) }
790+ | '<=' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, LtE, a) }
791+ | '<' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Lt, a) }
792+ | '>=' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, GtE, a) }
793+ | '>' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Gt, a) }
794+ | 'not' 'in' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, NotIn, a) }
795+ | 'in' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, In, a) }
796+ | 'is' 'not' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, IsNot, a) }
797+ | 'is' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Is, a) }
816798
817799# Bitwise operators
818800# -----------------
@@ -1014,14 +996,20 @@ strings[expr_ty] (memo):
1014996 | a[asdl_expr_seq*]=(fstring|string)+ { _PyPegen_concatenate_strings(p, a, EXTRA) }
1015997 | a[asdl_expr_seq*]=tstring+ { _PyPegen_concatenate_tstrings(p, a, EXTRA) }
1016998
999+ display_items[asdl_expr_seq*]: a[asdl_expr_seq*]=','.display_item+ [','] { a }
1000+
1001+ display_item[expr_ty]:
1002+ | invalid_starred_expression_unpacking_sequence
1003+ | star_named_expression
1004+
10171005list[expr_ty]:
1018- | '[' a=[star_named_expressions_sequence ] ']' { _PyAST_List(a, Load, EXTRA) }
1006+ | '[' a=[display_items ] ']' { _PyAST_List(a, Load, EXTRA) }
10191007
10201008tuple[expr_ty]:
1021- | '(' a=[y=star_named_expression_sequence ',' z=[star_named_expressions_sequence ] { _PyPegen_seq_insert_in_front(p, y, z) } ] ')' {
1009+ | '(' a=[y=display_item ',' z=[display_items ] { _PyPegen_seq_insert_in_front(p, y, z) } ] ')' {
10221010 _PyAST_Tuple(a, Load, EXTRA) }
10231011
1024- set[expr_ty]: '{' a=star_named_expressions_sequence '}' { _PyAST_Set(a, EXTRA) }
1012+ set[expr_ty]: '{' a=display_items '}' { _PyAST_Set(a, EXTRA) }
10251013
10261014# Dicts
10271015# -----
@@ -1088,8 +1076,8 @@ args[expr_ty]:
10881076 EXTRA) }
10891077
10901078kwargs[asdl_seq*]:
1091- | a=','.kwarg_or_starred+ ',' b =','.kwarg_or_double_starred+ { _PyPegen_join_sequences(p, a, b) }
1092- | ','.kwarg_or_starred+
1079+ | a=','.kwarg_or_starred+ b=[ ',' c =','.kwarg_or_double_starred+ { c }] {
1080+ b ? _PyPegen_join_sequences(p, a, b) : a }
10931081 | ','.kwarg_or_double_starred+
10941082
10951083starred_expression[expr_ty]:
@@ -1115,72 +1103,36 @@ kwarg_or_double_starred[KeywordOrStarred*]:
11151103# Generic targets
11161104# ---------------
11171105
1118- # NOTE: star_targets may contain *bitwise_or, targets may not .
1106+ # Targets reuse primary. Copying the context leaves its cached values in Load .
11191107star_targets[expr_ty]:
11201108 | a=star_target !',' { a }
11211109 | a=star_target b=(',' c=star_target { c })* [','] {
11221110 _PyAST_Tuple(CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)), Store, EXTRA) }
11231111
1124- star_targets_list_seq[asdl_expr_seq*]: a[asdl_expr_seq*]=','.star_target+ [','] { a }
1125-
1126- star_targets_tuple_seq[asdl_expr_seq*]:
1127- | a=star_target b=(',' c=star_target { c })+ [','] { (asdl_expr_seq*) _PyPegen_seq_insert_in_front(p, a, b) }
1128- | a=star_target ',' { (asdl_expr_seq*) _PyPegen_singleton_seq(p, a) }
1129-
11301112star_target[expr_ty] (memo):
11311113 | '*' a=(!'*' star_target) {
1132- _PyAST_Starred(CHECK(expr_ty, _PyPegen_set_expr_context(p, a, Store)) , Store, EXTRA) }
1133- | target_with_star_atom
1114+ _PyAST_Starred(a , Store, EXTRA) }
1115+ | target
11341116
1135- target_with_star_atom[expr_ty] (memo):
1136- | a=t_primary '.' b=NAME !t_lookahead { _PyAST_Attribute(a, b->v.Name.id, Store, EXTRA) }
1137- | a=t_primary '[' b=slices ']' !t_lookahead { _PyAST_Subscript(a, b, Store, EXTRA) }
1138- | star_atom
1139-
1140- star_atom[expr_ty]:
1141- | a=NAME { _PyPegen_set_expr_context(p, a, Store) }
1142- | '(' a=target_with_star_atom ')' { _PyPegen_set_expr_context(p, a, Store) }
1143- | '(' a=[star_targets_tuple_seq] ')' { _PyAST_Tuple(a, Store, EXTRA) }
1144- | '[' a=[star_targets_list_seq] ']' { _PyAST_List(a, Store, EXTRA) }
1117+ target[expr_ty] (memo):
1118+ | a=target_value { _PyPegen_make_target(p, a, STAR_TARGETS) }
11451119
11461120single_target[expr_ty]:
1147- | single_subscript_attribute_target
1148- | a=NAME { _PyPegen_set_expr_context(p, a, Store) }
1149- | '(' a=single_target ')' { a }
1150-
1151- single_subscript_attribute_target[expr_ty]:
1152- | a=t_primary '.' b=NAME !t_lookahead { _PyAST_Attribute(a, b->v.Name.id, Store, EXTRA) }
1153- | a=t_primary '[' b=slices ']' !t_lookahead { _PyAST_Subscript(a, b, Store, EXTRA) }
1154-
1155- t_primary[expr_ty]:
1156- | a=t_primary '.' b=NAME &t_lookahead { _PyAST_Attribute(a, b->v.Name.id, Load, EXTRA) }
1157- | a=t_primary '[' b=slices ']' &t_lookahead { _PyAST_Subscript(a, b, Load, EXTRA) }
1158- | a=t_primary b=genexp &t_lookahead {
1159- _PyAST_Call(a, CHECK(asdl_expr_seq*, (asdl_expr_seq*)_PyPegen_singleton_seq(p, b)), NULL, EXTRA) }
1160- | a=t_primary '(' b=[arguments] ')' &t_lookahead {
1161- _PyAST_Call(a,
1162- (b) ? ((expr_ty) b)->v.Call.args : NULL,
1163- (b) ? ((expr_ty) b)->v.Call.keywords : NULL,
1164- EXTRA) }
1165- | a=atom &t_lookahead { a }
1121+ | a=target_value { _PyPegen_make_target(p, a, SINGLE_TARGETS) }
1122+
1123+ attribute_or_subscript_target[expr_ty]:
1124+ | a=target_value { _PyPegen_make_target(p, a, ATTRIBUTE_OR_SUBSCRIPT_TARGETS) }
11661125
1167- t_lookahead: '(' | '[' | '.'
1126+ target_value[expr_ty]:
1127+ | a=primary !('(' | '[' | '.') { a }
11681128
11691129# Targets for del statements
11701130# --------------------------
11711131
11721132del_targets[asdl_expr_seq*]: a[asdl_expr_seq*]=','.del_target+ [','] { a }
11731133
11741134del_target[expr_ty] (memo):
1175- | a=t_primary '.' b=NAME !t_lookahead { _PyAST_Attribute(a, b->v.Name.id, Del, EXTRA) }
1176- | a=t_primary '[' b=slices ']' !t_lookahead { _PyAST_Subscript(a, b, Del, EXTRA) }
1177- | del_t_atom
1178-
1179- del_t_atom[expr_ty]:
1180- | a=NAME { _PyPegen_set_expr_context(p, a, Del) }
1181- | '(' a=del_target ')' { _PyPegen_set_expr_context(p, a, Del) }
1182- | '(' a=[del_targets] ')' { _PyAST_Tuple(a, Del, EXTRA) }
1183- | '[' a=[del_targets] ']' { _PyAST_List(a, Del, EXTRA) }
1135+ | a=target_value { _PyPegen_make_target(p, a, DEL_TARGETS) }
11841136
11851137# TYPING ELEMENTS
11861138# ---------------
0 commit comments