def METHOD_NAME(self, start, end):
    self.startStyling(start)
    text = self.parent().text()[start:end]
    last_pos = 0
    try:
        for token in self.lark.lex(text):
            ws_len = token.start_pos - last_pos
            if ws_len:
                self.setStyling(ws_len, 0)    # whitespace
            token_len = len(bytearray(token, "utf-8"))
            self.setStyling(
                token_len, self.token_styles.get(token.type, 0))
            last_pos = token.start_pos + token_len
    except Exception as e:
        print(e)