@@ -251,25 +251,7 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
251251 const char * line_start ;
252252
253253 type = PyTokenizer_Get (tok , & a , & b );
254- if (type == ERRORTOKEN ) {
255- err_ret -> error = tok -> done ;
256- break ;
257- }
258- if (type == ENDMARKER && started ) {
259- type = NEWLINE ; /* Add an extra newline */
260- started = 0 ;
261- /* Add the right number of dedent tokens,
262- except if a certain flag is given --
263- codeop.py uses this. */
264- if (tok -> indent &&
265- !(* flags & PyPARSE_DONT_IMPLY_DEDENT ))
266- {
267- tok -> pendin = - tok -> indent ;
268- tok -> indent = 0 ;
269- }
270- }
271- else
272- started = 1 ;
254+
273255 len = (a != NULL && b != NULL ) ? b - a : 0 ;
274256 str = (char * ) PyObject_MALLOC (len + 1 );
275257 if (str == NULL ) {
@@ -328,6 +310,27 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
328310 continue ;
329311 }
330312
313+ if (type == ERRORTOKEN ) {
314+ err_ret -> error = tok -> done ;
315+ break ;
316+ }
317+ if (type == ENDMARKER && started ) {
318+ type = NEWLINE ; /* Add an extra newline */
319+ started = 0 ;
320+ /* Add the right number of dedent tokens,
321+ except if a certain flag is given --
322+ codeop.py uses this. */
323+ if (tok -> indent &&
324+ !(* flags & PyPARSE_DONT_IMPLY_DEDENT ))
325+ {
326+ tok -> pendin = - tok -> indent ;
327+ tok -> indent = 0 ;
328+ }
329+ }
330+ else {
331+ started = 1 ;
332+ }
333+
331334 if ((err_ret -> error =
332335 PyParser_AddToken (ps , (int )type , str ,
333336 lineno , col_offset , tok -> lineno , end_col_offset ,
0 commit comments