Enum attribute
enum_attribute
EnumType = TypeVar('EnumType', bound=StrEnum)
module-attribute
EnumAttribute
dataclass
Helper for Enum Attributes. Takes a StrEnum type parameter, and defines parsing/printing automatically from its values, restricted to be parsable as identifiers.
example:
class MyEnum(StrEnum):
First = auto()
Second = auto()
class MyEnumAttribute(EnumAttribute[MyEnum], SpacedOpaqueSyntaxAttribute):
name = "example.my_enum"
To use this attribute suffices to have a textual representation
of example<my_enum first> and example<my_enum second>
Source code in xdsl/dialects/utils/enum_attribute.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
enum_type: type[StrEnum]
class-attribute
__init_subclass__() -> None
Extract and store the Enum type used by the subclass for use in parsing/printing.
Subclass implementations are also constrained to keep implementations reasonable, unless more complex use cases appear.
The constraint(s) are: - Only direct, specialized inheritance is allowed. That is, using a subclass of EnumAttribute as a base class is not supported. This simplifies type-hacking code and I don't see it being too restrictive anytime soon.
Source code in xdsl/dialects/utils/enum_attribute.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
print_parameter(printer: Printer) -> None
Source code in xdsl/dialects/utils/enum_attribute.py
61 62 | |
parse_parameter(parser: AttrParser) -> EnumType
classmethod
Source code in xdsl/dialects/utils/enum_attribute.py
64 65 66 | |