#  Copyright (c) PARRRATE T&V 2021. All rights reserved.

from bu4.evaluation.av.evtype import evtype
from bu4.evaluation.constructs.eexception import EException
from bu4.evaluation.constructs.evaluable import Evaluable
from bu4.indexing.constructs.indexed import Indexed
from bu4.parsing.codes import CODE_XCPT

__all__ = ('IException',)


class IException(Indexed):
    def __init__(self, name: bytes):
        self.name = name

    def attach(self, ev: evtype) -> Evaluable:
        return EException(self.name)

    def __str__(self):
        return f'«{self.name.decode()}»'

    def __bytes__(self):
        return bytes([CODE_XCPT, *self.name, 0])