@@ -274,7 +274,7 @@ raise_unclosed_parentheses_error(Parser *p) {
274
274
int error_lineno = p -> tok -> parenlinenostack [p -> tok -> level - 1 ];
275
275
int error_col = p -> tok -> parencolstack [p -> tok -> level - 1 ];
276
276
RAISE_ERROR_KNOWN_LOCATION (p , PyExc_SyntaxError ,
277
- error_lineno , error_col ,
277
+ error_lineno , error_col , error_lineno , -1 ,
278
278
"'%c' was never closed" ,
279
279
p -> tok -> parenstack [p -> tok -> level - 1 ]);
280
280
}
@@ -366,7 +366,7 @@ tokenizer_error(Parser *p)
366
366
msg = "unknown parsing error" ;
367
367
}
368
368
369
- RAISE_ERROR_KNOWN_LOCATION (p , errtype , p -> tok -> lineno , col_offset , msg );
369
+ RAISE_ERROR_KNOWN_LOCATION (p , errtype , p -> tok -> lineno , col_offset , p -> tok -> lineno , -1 , msg );
370
370
return -1 ;
371
371
}
372
372
@@ -375,17 +375,21 @@ _PyPegen_raise_error(Parser *p, PyObject *errtype, const char *errmsg, ...)
375
375
{
376
376
Token * t = p -> known_err_token != NULL ? p -> known_err_token : p -> tokens [p -> fill - 1 ];
377
377
Py_ssize_t col_offset ;
378
+ Py_ssize_t end_col_offset = -1 ;
378
379
if (t -> col_offset == -1 ) {
379
380
col_offset = Py_SAFE_DOWNCAST (p -> tok -> cur - p -> tok -> buf ,
380
381
intptr_t , int );
381
382
} else {
382
383
col_offset = t -> col_offset + 1 ;
383
384
}
384
385
386
+ if (t -> end_col_offset != -1 ) {
387
+ end_col_offset = t -> end_col_offset + 1 ;
388
+ }
389
+
385
390
va_list va ;
386
391
va_start (va , errmsg );
387
- _PyPegen_raise_error_known_location (p , errtype , t -> lineno ,
388
- col_offset , errmsg , va );
392
+ _PyPegen_raise_error_known_location (p , errtype , t -> lineno , col_offset , t -> end_lineno , end_col_offset , errmsg , va );
389
393
va_end (va );
390
394
391
395
return NULL ;
@@ -416,6 +420,7 @@ get_error_line(Parser *p, Py_ssize_t lineno)
416
420
void *
417
421
_PyPegen_raise_error_known_location (Parser * p , PyObject * errtype ,
418
422
Py_ssize_t lineno , Py_ssize_t col_offset ,
423
+ Py_ssize_t end_lineno , Py_ssize_t end_col_offset ,
419
424
const char * errmsg , va_list va )
420
425
{
421
426
PyObject * value = NULL ;
@@ -424,6 +429,13 @@ _PyPegen_raise_error_known_location(Parser *p, PyObject *errtype,
424
429
PyObject * tmp = NULL ;
425
430
p -> error_indicator = 1 ;
426
431
432
+ if (end_lineno == CURRENT_POS ) {
433
+ end_lineno = p -> tok -> lineno ;
434
+ }
435
+ if (end_col_offset == CURRENT_POS ) {
436
+ end_col_offset = p -> tok -> cur - p -> tok -> line_start ;
437
+ }
438
+
427
439
if (p -> start_rule == Py_fstring_input ) {
428
440
const char * fstring_msg = "f-string: " ;
429
441
Py_ssize_t len = strlen (fstring_msg ) + strlen (errmsg );
@@ -475,14 +487,19 @@ _PyPegen_raise_error_known_location(Parser *p, PyObject *errtype,
475
487
476
488
if (p -> start_rule == Py_fstring_input ) {
477
489
col_offset -= p -> starting_col_offset ;
490
+ end_col_offset -= p -> starting_col_offset ;
478
491
}
492
+
479
493
Py_ssize_t col_number = col_offset ;
494
+ Py_ssize_t end_col_number = end_col_offset ;
480
495
481
496
if (p -> tok -> encoding != NULL ) {
482
497
col_number = byte_offset_to_character_offset (error_line , col_offset );
498
+ end_col_number = end_col_number > 0 ?
499
+ byte_offset_to_character_offset (error_line , end_col_offset ) :
500
+ end_col_number ;
483
501
}
484
-
485
- tmp = Py_BuildValue ("(OiiN)" , p -> tok -> filename , lineno , col_number , error_line );
502
+ tmp = Py_BuildValue ("(OiiNii)" , p -> tok -> filename , lineno , col_number , error_line , end_lineno , end_col_number );
486
503
if (!tmp ) {
487
504
goto error ;
488
505
}
@@ -1494,6 +1511,13 @@ _PyPegen_seq_flatten(Parser *p, asdl_seq *seqs)
1494
1511
return flattened_seq ;
1495
1512
}
1496
1513
1514
+ void *
1515
+ _PyPegen_seq_last_item (asdl_seq * seq )
1516
+ {
1517
+ Py_ssize_t len = asdl_seq_LEN (seq );
1518
+ return asdl_seq_GET_UNTYPED (seq , len - 1 );
1519
+ }
1520
+
1497
1521
/* Creates a new name of the form <first_name>.<second_name> */
1498
1522
expr_ty
1499
1523
_PyPegen_join_names_with_dot (Parser * p , expr_ty first_name , expr_ty second_name )
@@ -2398,7 +2422,7 @@ _PyPegen_nonparen_genexp_in_call(Parser *p, expr_ty args)
2398
2422
return NULL ;
2399
2423
}
2400
2424
2401
- return RAISE_SYNTAX_ERROR_KNOWN_LOCATION (
2425
+ return RAISE_SYNTAX_ERROR_STARTING_FROM (
2402
2426
(expr_ty ) asdl_seq_GET (args -> v .Call .args , len - 1 ),
2403
2427
"Generator expression must be parenthesized"
2404
2428
);
0 commit comments