@staticmethod
def set_state(block, state):
    """
        Sets the user state, generally used for syntax highlighting.

        :param block: block to modify
        :param state: new state value.
        :return:
        """
    if block is None:
        return
    user_state = block.userState()
    if user_state == -1:
        user_state = 0
    higher_part = user_state & 2147418112
    state &= 65535
    state |= higher_part
    block.setUserState(state)
