@@ -144,7 +144,7 @@ def rule(parser):
144
144
145
145
error_tok = parser ._tokens [parser ._errindex ]
146
146
error = diagnostic .Diagnostic (
147
- "error " , "unexpected {actual}: expected {expected}" ,
147
+ "fatal " , "unexpected {actual}: expected {expected}" ,
148
148
{'actual' : error_tok .kind , 'expected' : expected },
149
149
error_tok .loc )
150
150
raise diagnostic .DiagnosticException (error )
@@ -360,9 +360,6 @@ def _save(self):
360
360
return self ._index
361
361
362
362
def _restore (self , data , rule ):
363
- if self ._index == data :
364
- return
365
-
366
363
self ._index = data
367
364
self ._token = self ._tokens [self ._index ]
368
365
@@ -411,10 +408,10 @@ def _assignable(self, node, is_delete=False):
411
408
else :
412
409
if is_delete :
413
410
error = diagnostic .Diagnostic (
414
- "error " , "cannot delete this expression" , {}, node .loc )
411
+ "fatal " , "cannot delete this expression" , {}, node .loc )
415
412
else :
416
413
error = diagnostic .Diagnostic (
417
- "error " , "cannot assign to this expression" , {}, node .loc )
414
+ "fatal " , "cannot assign to this expression" , {}, node .loc )
418
415
raise diagnostic .DiagnosticException (error )
419
416
420
417
def _empty_arguments (self ):
@@ -537,16 +534,18 @@ def varargslist(self, fparams, args):
537
534
('*' NAME [',' '**' NAME] | '**' NAME) |
538
535
fpdef ['=' test] (',' fpdef ['=' test])* [','])"""
539
536
for fparam , default_opt in fparams :
540
- args .args .append (fparam )
541
537
if default_opt :
542
538
equals_loc , default = default_opt
543
539
args .equals_locs .append (equals_loc )
544
540
args .defaults .append (default )
545
541
elif len (args .defaults ) > 0 :
546
542
error = diagnostic .Diagnostic (
547
- "error" , "non-default argument follows default argument" , {}, fparam .loc )
543
+ "fatal" , "non-default argument follows default argument" , {},
544
+ fparam .loc , [args .args [- 1 ].loc .join (args .defaults [- 1 ].loc )])
548
545
raise diagnostic .DiagnosticException (error )
549
546
547
+ args .args .append (fparam )
548
+
550
549
def fparam_loc (fparam , default_opt ):
551
550
if default_opt :
552
551
equals_loc , default = default_opt
@@ -603,9 +602,10 @@ def expr_stmt(self, lhs, rhs):
603
602
"""expr_stmt: testlist (augassign (yield_expr|testlist) |
604
603
('=' (yield_expr|testlist))*)"""
605
604
if isinstance (rhs , ast .AugAssign ):
606
- if isinstance (lhs , ast .Tuple ):
605
+ if isinstance (lhs , ast .Tuple ) or isinstance ( lhs , ast . List ) :
607
606
error = diagnostic .Diagnostic (
608
- "error" , "illegal expression for augmented assignment" , {}, rhs .loc )
607
+ "fatal" , "illegal expression for augmented assignment" , {},
608
+ rhs .op .loc , [lhs .loc ])
609
609
raise diagnostic .DiagnosticException (error )
610
610
else :
611
611
rhs .target = self ._assignable (lhs )
@@ -859,14 +859,16 @@ def if_stmt(self, if_loc, test, if_colon_loc, body, elifs, else_opt):
859
859
for elif_ in elifs :
860
860
stmt .keyword_loc , stmt .test , stmt .if_colon_loc , stmt .body = elif_
861
861
stmt .loc = stmt .keyword_loc .join (stmt .body [- 1 ].loc )
862
- if stmt .orelse : stmt .loc = stmt .loc .join (stmt .orelse [- 1 ].loc )
862
+ if stmt .orelse :
863
+ stmt .loc = stmt .loc .join (stmt .orelse [- 1 ].loc )
863
864
stmt = ast .If (orelse = [stmt ],
864
865
else_loc = None , else_colon_loc = None )
865
866
866
867
stmt .keyword_loc , stmt .test , stmt .if_colon_loc , stmt .body = \
867
868
if_loc , test , if_colon_loc , body
868
869
stmt .loc = stmt .keyword_loc .join (stmt .body [- 1 ].loc )
869
- if stmt .orelse : stmt .loc = stmt .loc .join (stmt .orelse [- 1 ].loc )
870
+ if stmt .orelse :
871
+ stmt .loc = stmt .loc .join (stmt .orelse [- 1 ].loc )
870
872
return stmt
871
873
872
874
@action (Seq (Loc ('while' ), Rule ('test' ), Loc (':' ), Rule ('suite' ),
@@ -1307,7 +1309,8 @@ def arglist_2(self, star_loc, stararg, postargs, kwarg_opt):
1307
1309
for postarg in postargs :
1308
1310
if not isinstance (postarg , ast .keyword ):
1309
1311
error = diagnostic .Diagnostic (
1310
- "error" , "only named arguments may follow *expression" , {}, postarg .loc )
1312
+ "fatal" , "only named arguments may follow *expression" , {},
1313
+ postarg .loc , [star_loc .join (stararg .loc )])
1311
1314
raise diagnostic .DiagnosticException (error )
1312
1315
1313
1316
return postargs , \
@@ -1344,7 +1347,8 @@ def arglist(self, pre_args, rest):
1344
1347
call .keywords .append (arg )
1345
1348
elif len (call .keywords ) > 0 :
1346
1349
error = diagnostic .Diagnostic (
1347
- "error" , "non-keyword arg after keyword arg" , {}, arg .loc )
1350
+ "fatal" , "non-keyword arg after keyword arg" , {},
1351
+ arg .loc , [call .keywords [- 1 ].loc ])
1348
1352
raise diagnostic .DiagnosticException (error )
1349
1353
else :
1350
1354
call .args .append (arg )
@@ -1355,7 +1359,7 @@ def argument_1(self, equals_loc, rhs):
1355
1359
def thunk (lhs ):
1356
1360
if not isinstance (lhs , ast .Name ):
1357
1361
error = diagnostic .Diagnostic (
1358
- "error " , "keyword must be an identifier" , {}, lhs .loc )
1362
+ "fatal " , "keyword must be an identifier" , {}, lhs .loc )
1359
1363
raise diagnostic .DiagnosticException (error )
1360
1364
return ast .keyword (arg = lhs .id , value = rhs ,
1361
1365
loc = lhs .loc .join (rhs .loc ),
0 commit comments