    def parse(self):
        """
        Generator to return coloured text from raw text.

        :returns: a 3-tuple of (start offset in raw text, command to execute, parameters)
        """
        if self._state.attributes:
            yield (0, Parser.CHANGE_COLOURS, tuple(self._state.attributes))
        offset = last_offset = 0
        while len(self._state.text) > 0:
            match = self._colour_sequence.match(str(self._state.text))
            if match is None:
                yield (last_offset, Parser.DISPLAY_TEXT, self._state.text[0])
                self._state.text = self._state.text[1:]
                offset += 1
                last_offset = offset
            else:
                # The regexp either matches:
                # - 2,3,4 for ${c,a,b}
                # - 5,6 for ${c,a}
                # - 7 for ${c}.
                if match.group(2) is not None:
                    attributes = (int(match.group(2)),
                                  constants.MAPPING_ATTRIBUTES[match.group(3)],
                                  int(match.group(4)))
                elif match.group(5) is not None:
                    attributes = (int(match.group(5)),
                                  constants.MAPPING_ATTRIBUTES[match.group(6)],
                                  None)
                else:
                    attributes = (int(match.group(7)), 0, None)
                yield (last_offset, Parser.CHANGE_COLOURS, attributes)
                offset += 3 + len(match.group(1))
                self._state.text = match.group(8)
Generator to return coloured text from raw text.

:returns: a 3-tuple of (start offset in raw text, command to execute, parameters)
asciimatics/parsers.py