code: def parse(self, format_string):
          
          txt, state = '', 0
          colorstack = [(None, None)]
          itokens = self.tokenize(format_string)
  
          for token, escaped in itokens:
              if token == self._START_TOKEN and not escaped:
                  if txt:
                      yield txt, colorstack[-1]
                      txt = ''
  
                  state += 1
                  colors = self.extract_syntax(colorise.compat.next(itokens)[0])
                  colorstack.append(tuple(b or a
                                          for a, b in zip(colorstack[-1],
                                                          colors)))
              elif token == self._FMT_TOKEN and not escaped:
                  # if state == 0:
                  #     raise ColorSyntaxError("Missing '{0}'"
                  #                            .format(self._START_TOKEN))
  
                  if state % 2 != 0:
                      state += 1
                  else:
                      txt += token
              elif token == self._STOP_TOKEN and not escaped:
                  if state < 2:
                      raise ColorSyntaxError("Missing '{0}' or '{1}'"
                                             .format(self._STOP_TOKEN,
                                                     self._FMT_TOKEN))
  
                  if txt:
                      yield txt, colorstack[-1]
                      txt = ''
  
                  state -= 2
                  colorstack.pop()
              else:
                  txt += token
  
          if state != 0:
              raise ColorSyntaxError("Invalid color format")
  
          if txt:
              yield txt, colorstack[-1]
docs: Parse color syntax from a formatted string.