@@ -779,32 +779,32 @@ t_atom[expr_ty]:
779
779
780
780
# From here on, there are rules for invalid syntax with specialised error messages
781
781
invalid_arguments:
782
- | args ',' '*' { RAISE_SYNTAX_ERROR( "iterable argument unpacking follows keyword argument unpacking") }
783
- | a=expression for_if_clauses ',' [args | expression for_if_clauses] {
784
- RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a , "Generator expression must be parenthesized") }
782
+ | a= args ',' '*' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "iterable argument unpacking follows keyword argument unpacking") }
783
+ | a=expression b= for_if_clauses ',' [args | expression for_if_clauses] {
784
+ RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, asdl_seq_GET(b, b->size-1)->target , "Generator expression must be parenthesized") }
785
785
| a=args for_if_clauses { _PyPegen_nonparen_genexp_in_call(p, a) }
786
- | args ',' a=expression for_if_clauses {
787
- RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a , "Generator expression must be parenthesized") }
786
+ | args ',' a=expression b= for_if_clauses {
787
+ RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, asdl_seq_GET(b, b->size-1)->target , "Generator expression must be parenthesized") }
788
788
| a=args ',' args { _PyPegen_arguments_parsing_error(p, a) }
789
789
invalid_kwarg:
790
- | expression a ='=' {
791
- RAISE_SYNTAX_ERROR_KNOWN_LOCATION (
792
- a, "expression cannot contain assignment, perhaps you meant \"==\"?") }
790
+ | a= expression b ='=' {
791
+ RAISE_SYNTAX_ERROR_KNOWN_RANGE (
792
+ a, b, "expression cannot contain assignment, perhaps you meant \"==\"?") }
793
793
794
794
invalid_expression:
795
795
# !(NAME STRING) is not matched so we don't show this error with some invalid string prefixes like: kf"dsfsdf"
796
796
# Soft keywords need to also be ignored because they can be parsed as NAME NAME
797
- | !(NAME STRING | SOFT_KEYWORD) a=disjunction expression {
798
- RAISE_ERROR_KNOWN_LOCATION(p, PyExc_SyntaxError, a->lineno, a->end_col_offset - 1 , "invalid syntax. Perhaps you forgot a comma?") }
797
+ | !(NAME STRING | SOFT_KEYWORD) a=disjunction b= expression {
798
+ RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b , "invalid syntax. Perhaps you forgot a comma?") }
799
799
800
800
invalid_named_expression:
801
801
| a=expression ':=' expression {
802
802
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
803
803
a, "cannot use assignment expressions with %s", _PyPegen_get_expr_name(a)) }
804
- | a=NAME b= '=' bitwise_or !('='|':='|',') {
805
- RAISE_SYNTAX_ERROR_KNOWN_LOCATION( b, "invalid syntax. Maybe you meant '==' or ':=' instead of '='?") }
804
+ | a=NAME '=' b= bitwise_or !('='|':='|',') {
805
+ RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '==' or ':=' instead of '='?") }
806
806
| !(list|tuple|genexp|'True'|'None'|'False') a=bitwise_or b='=' bitwise_or !('='|':='|',') {
807
- RAISE_SYNTAX_ERROR_KNOWN_LOCATION(b , "cannot assign to %s here. Maybe you meant '==' instead of '='?",
807
+ RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a , "cannot assign to %s here. Maybe you meant '==' instead of '='?",
808
808
_PyPegen_get_expr_name(a)) }
809
809
810
810
invalid_assignment:
@@ -841,25 +841,28 @@ invalid_primary:
841
841
invalid_comprehension:
842
842
| ('[' | '(' | '{') a=starred_expression for_if_clauses {
843
843
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "iterable unpacking cannot be used in comprehension") }
844
- | ('[' | '{') a=star_named_expression ',' [star_named_expressions] for_if_clauses {
845
- RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "did you forget parentheses around the comprehension target?") }
844
+ | ('[' | '{') a=star_named_expression ',' b=star_named_expressions for_if_clauses {
845
+ RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, (expr_ty)_PyPegen_seq_last_item((asdl_seq*)b),
846
+ "did you forget parentheses around the comprehension target?") }
847
+ | ('[' | '{') a=star_named_expression b=',' for_if_clauses {
848
+ RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "did you forget parentheses around the comprehension target?") }
846
849
invalid_dict_comprehension:
847
850
| '{' a='**' bitwise_or for_if_clauses '}' {
848
851
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "dict unpacking cannot be used in dict comprehension") }
849
852
invalid_parameters:
850
- | param_no_default* invalid_parameters_helper param_no_default {
851
- RAISE_SYNTAX_ERROR( "non-default argument follows default argument") }
853
+ | param_no_default* invalid_parameters_helper a= param_no_default {
854
+ RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "non-default argument follows default argument") }
852
855
invalid_parameters_helper: # This is only there to avoid type errors
853
856
| a=slash_with_default { _PyPegen_singleton_seq(p, a) }
854
857
| param_with_default+
855
858
invalid_lambda_parameters:
856
- | lambda_param_no_default* invalid_lambda_parameters_helper lambda_param_no_default {
857
- RAISE_SYNTAX_ERROR( "non-default argument follows default argument") }
859
+ | lambda_param_no_default* invalid_lambda_parameters_helper a= lambda_param_no_default {
860
+ RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "non-default argument follows default argument") }
858
861
invalid_lambda_parameters_helper:
859
862
| a=lambda_slash_with_default { _PyPegen_singleton_seq(p, a) }
860
863
| lambda_param_with_default+
861
864
invalid_star_etc:
862
- | '*' (')' | ',' (')' | '**')) { RAISE_SYNTAX_ERROR( "named arguments must follow bare *") }
865
+ | a= '*' (')' | ',' (')' | '**')) { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "named arguments must follow bare *") }
863
866
| '*' ',' TYPE_COMMENT { RAISE_SYNTAX_ERROR("bare * has associated type comment") }
864
867
invalid_lambda_star_etc:
865
868
| '*' (':' | ',' (':' | '**')) { RAISE_SYNTAX_ERROR("named arguments must follow bare *") }
@@ -897,7 +900,7 @@ invalid_try_stmt:
897
900
RAISE_INDENTATION_ERROR("expected an indented block after 'try' statement on line %d", a->lineno) }
898
901
invalid_except_stmt:
899
902
| 'except' a=expression ',' expressions ['as' NAME ] ':' {
900
- RAISE_SYNTAX_ERROR_KNOWN_LOCATION (a, "exception group must be parenthesized") }
903
+ RAISE_SYNTAX_ERROR_STARTING_FROM (a, "exception group must be parenthesized") }
901
904
| a='except' expression ['as' NAME ] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
902
905
| a='except' NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
903
906
invalid_finally_stmt:
@@ -942,10 +945,10 @@ invalid_class_def_raw:
942
945
943
946
invalid_double_starred_kvpairs:
944
947
| ','.double_starred_kvpair+ ',' invalid_kvpair
945
- | expression ':' a='*' bitwise_or { RAISE_SYNTAX_ERROR_KNOWN_LOCATION (a, "cannot use a starred expression in a dictionary value") }
948
+ | expression ':' a='*' bitwise_or { RAISE_SYNTAX_ERROR_STARTING_FROM (a, "cannot use a starred expression in a dictionary value") }
946
949
| expression a=':' &('}'|',') { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "expression expected after dictionary key and ':'") }
947
950
invalid_kvpair:
948
951
| a=expression !(':') {
949
- RAISE_ERROR_KNOWN_LOCATION(p, PyExc_SyntaxError, a->lineno, a->end_col_offset - 1, "':' expected after dictionary key") }
950
- | expression ':' a='*' bitwise_or { RAISE_SYNTAX_ERROR_KNOWN_LOCATION (a, "cannot use a starred expression in a dictionary value") }
952
+ RAISE_ERROR_KNOWN_LOCATION(p, PyExc_SyntaxError, a->lineno, a->end_col_offset - 1, a->end_lineno, -1, "':' expected after dictionary key") }
953
+ | expression ':' a='*' bitwise_or { RAISE_SYNTAX_ERROR_STARTING_FROM (a, "cannot use a starred expression in a dictionary value") }
951
954
| expression a=':' {RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "expression expected after dictionary key and ':'") }
0 commit comments