@@ -265,6 +265,16 @@ raise_decode_error(Parser *p)
265
265
return -1 ;
266
266
}
267
267
268
+ static inline void
269
+ raise_unclosed_parentheses_error (Parser * p ) {
270
+ int error_lineno = p -> tok -> parenlinenostack [p -> tok -> level - 1 ];
271
+ int error_col = p -> tok -> parencolstack [p -> tok -> level - 1 ];
272
+ RAISE_ERROR_KNOWN_LOCATION (p , PyExc_SyntaxError ,
273
+ error_lineno , error_col ,
274
+ "'%c' was never closed" ,
275
+ p -> tok -> parenstack [p -> tok -> level - 1 ]);
276
+ }
277
+
268
278
static void
269
279
raise_tokenizer_init_error (PyObject * filename )
270
280
{
@@ -325,11 +335,7 @@ tokenizer_error(Parser *p)
325
335
return -1 ;
326
336
case E_EOF :
327
337
if (p -> tok -> level ) {
328
- RAISE_ERROR_KNOWN_LOCATION (p , PyExc_SyntaxError ,
329
- p -> tok -> parenlinenostack [p -> tok -> level - 1 ],
330
- p -> tok -> parencolstack [p -> tok -> level - 1 ],
331
- "'%c' was never closed" ,
332
- p -> tok -> parenstack [p -> tok -> level - 1 ]);
338
+ raise_unclosed_parentheses_error (p );
333
339
} else {
334
340
RAISE_SYNTAX_ERROR ("unexpected EOF while parsing" );
335
341
}
@@ -1159,7 +1165,7 @@ reset_parser_state(Parser *p)
1159
1165
p -> call_invalid_rules = 1 ;
1160
1166
}
1161
1167
1162
- int
1168
+ static int
1163
1169
_PyPegen_check_tokenizer_errors (Parser * p ) {
1164
1170
// Tokenize the whole input to see if there are any tokenization
1165
1171
// errors such as mistmatching parentheses. These will get priority
@@ -1187,12 +1193,8 @@ _PyPegen_check_tokenizer_errors(Parser *p) {
1187
1193
if (type == ERRORTOKEN ) {
1188
1194
if (p -> tok -> level != 0 ) {
1189
1195
int error_lineno = p -> tok -> parenlinenostack [p -> tok -> level - 1 ];
1190
- int error_col = p -> tok -> parencolstack [p -> tok -> level - 1 ];
1191
1196
if (current_err_line > error_lineno ) {
1192
- RAISE_ERROR_KNOWN_LOCATION (p , PyExc_SyntaxError ,
1193
- error_lineno , error_col ,
1194
- "'%c' was never closed" ,
1195
- p -> tok -> parenstack [p -> tok -> level - 1 ]);
1197
+ raise_unclosed_parentheses_error (p );
1196
1198
return -1 ;
1197
1199
}
1198
1200
}
@@ -1221,11 +1223,7 @@ _PyPegen_run_parser(Parser *p)
1221
1223
}
1222
1224
else if (p -> tok -> done == E_EOF ) {
1223
1225
if (p -> tok -> level ) {
1224
- RAISE_ERROR_KNOWN_LOCATION (p , PyExc_SyntaxError ,
1225
- p -> tok -> parenlinenostack [p -> tok -> level - 1 ],
1226
- p -> tok -> parencolstack [p -> tok -> level - 1 ],
1227
- "'%c' was never closed" ,
1228
- p -> tok -> parenstack [p -> tok -> level - 1 ]);
1226
+ raise_unclosed_parentheses_error (p );
1229
1227
} else {
1230
1228
RAISE_SYNTAX_ERROR ("unexpected EOF while parsing" );
1231
1229
}
0 commit comments