original_docstring: Colorize a *single* line s
docstring: Colorize a *single* line s
docstring_tokens: Colorize a * single * line s
code: def mainLoop(self, s):
          """Colorize a *single* line s"""
          t1 = time.process_time()
          highlighter = self.highlighter
          #
          # First, set the *expected* lexer. It may change later.
          lexer = self.set_lexer()
          #
          # Restore the state.
          # Based on Jupyter code: (c) Jupyter Development Team.
          stack_ivar = '_saved_state_stack'
          prev_data = highlighter.currentBlock().previous().userData()
          if prev_data is not None:
              # New code by EKR. Restore the language if necessary.
              if self.language != prev_data.leo_language:
                  # Change the language and the lexer!
                  self.language = prev_data.leo_language
                  # g.trace('RESTORE:', self.language)
                  lexer = self.set_lexer()
              setattr(lexer, stack_ivar, prev_data.syntax_stack)
          elif hasattr(lexer, stack_ivar):
              delattr(lexer, stack_ivar)
          # g.trace(self.color_enabled, self.language, repr(s))
          #
          # The main loop. Warning: this can change self.language.
          index = 0
          for token, text in lexer.get_tokens(s):
              length = len(text)
              # print('%5s %25r %r' % (self.color_enabled, repr(token).lstrip('Token.'), text))
              if self.color_enabled:
                  format = self.getFormat(token, text)
              else:
                  format = self.getDefaultFormat()
              self.setFormat(index, length, format, s)
              index += length
          #
          # Save the state.
          # Based on Jupyter code: (c) Jupyter Development Team.
          stack = getattr(lexer, stack_ivar, None)
          if stack:
              data = PygmentsBlockUserData(syntax_stack=stack, leo_language=self.language)
              highlighter.currentBlock().setUserData(data)
              # Clean up for the next go-round.
              delattr(lexer, stack_ivar)
          #
          # New code by EKR:
          # - Fixes a bug so multiline tokens work.
          # - State supports Leo's color directives.
          state_s = f"{self.language}; {self.color_enabled}: {stack!r}"
          state_n = self.state_s_dict.get(state_s)
          if state_n is None:
              state_n = self.state_index
              self.state_index += 1
              self.state_s_dict[state_s] = state_n
              self.state_n_dict[state_n] = state_s
          highlighter.setCurrentBlockState(state_n)
          self.tot_time += time.process_time() - t1
code_tokens: def mainLoop ( self , s ) : t1 = time . process_time ( ) highlighter = self . highlighter lexer = self . set_lexer ( ) stack_ivar = '_saved_state_stack' prev_data = highlighter . currentBlock ( ) . previous ( ) . userData ( ) if prev_data is not None : if self . language != prev_data . leo_language : self . language = prev_data . leo_language lexer = self . set_lexer ( ) setattr ( lexer , stack_ivar , prev_data . syntax_stack ) elif hasattr ( lexer , stack_ivar ) : delattr ( lexer , stack_ivar ) index = 0 for token , text in lexer . get_tokens ( s ) : length = len ( text ) if self . color_enabled : format = self . getFormat ( token , text ) else : format = self . getDefaultFormat ( ) self . setFormat ( index , length , format , s ) index += length stack = getattr ( lexer , stack_ivar , None ) if stack : data = PygmentsBlockUserData ( syntax_stack = stack , leo_language = self . language ) highlighter . currentBlock ( ) . setUserData ( data ) delattr ( lexer , stack_ivar ) state_s = f"{self.language}; {self.color_enabled}: {stack!r}" state_n = self . state_s_dict . get ( state_s ) if state_n is None : state_n = self . state_index self . state_index += 1 self . state_s_dict [ state_s ] = state_n self . state_n_dict [ state_n ] = state_s highlighter . setCurrentBlockState ( state_n ) self . tot_time += time . process_time ( ) - t1
short_docstring: Colorize a *single* line s
short_docstring_tokens: Colorize a * single * line s
comment: """Colorize a *single* line s"""$SEP$#$SEP$# First, set the *expected* lexer. It may change later.$SEP$#$SEP$# Restore the state.$SEP$# Based on Jupyter code: (c) Jupyter Development Team.$SEP$# New code by EKR. Restore the language if necessary.$SEP$# Change the language and the lexer!$SEP$# g.trace('RESTORE:', self.language)$SEP$# g.trace(self.color_enabled, self.language, repr(s))$SEP$#$SEP$# The main loop. Warning: this can change self.language.$SEP$# print('%5s %25r %r' % (self.color_enabled, repr(token).lstrip('Token.'), text))$SEP$#$SEP$# Save the state.$SEP$# Based on Jupyter code: (c) Jupyter Development Team.$SEP$# Clean up for the next go-round.$SEP$#$SEP$# New code by EKR:$SEP$# - Fixes a bug so multiline tokens work.$SEP$# - State supports Leo's color directives.