@@ -679,15 +679,15 @@ def get_tokens_unprocessed(self, text):
679679 insertions = []
680680 curtb = ''
681681 tbindex = 0
682- tb = 0
682+ in_tb = False
683683 for match in line_re .finditer (text ):
684684 line = match .group ()
685685 if line .startswith ('>>> ' ) or line .startswith ('... ' ):
686- tb = 0
686+ in_tb = False
687687 insertions .append ((len (curcode ),
688688 [(0 , Generic .Prompt , line [:4 ])]))
689689 curcode += line [4 :]
690- elif line .rstrip () == '...' and not tb :
690+ elif line .rstrip () == '...' and not in_tb :
691691 # only a new >>> prompt can end an exception block
692692 # otherwise an ellipsis in place of the traceback frames
693693 # will be mishandled
@@ -700,20 +700,20 @@ def get_tokens_unprocessed(self, text):
700700 insertions , pylexer .get_tokens_unprocessed (curcode ))
701701 curcode = ''
702702 insertions = []
703- if (line .startswith ('Traceback (most recent call last):' ) or
704- re .match (' File "[^"]+", line \\ d+\\ n$' , line )):
705- tb = 1
706- curtb = line
707- tbindex = match .start ()
708- elif line == 'KeyboardInterrupt\n ' :
709- yield match .start (), Name .Class , line
710- elif tb :
703+ if in_tb :
711704 curtb += line
712705 if not (line .startswith (' ' ) or line .strip () == '...' ):
713- tb = 0
706+ in_tb = False
714707 for i , t , v in tblexer .get_tokens_unprocessed (curtb ):
715708 yield tbindex + i , t , v
716709 curtb = ''
710+ elif (line .startswith ('Traceback (most recent call last):' ) or
711+ re .match (' File "[^"]+", line \\ d+\\ n$' , line )):
712+ in_tb = True
713+ curtb = line
714+ tbindex = match .start ()
715+ elif line == 'KeyboardInterrupt\n ' :
716+ yield match .start (), Name .Class , line
717717 else :
718718 yield match .start (), Generic .Output , line
719719 if curcode :
0 commit comments