-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoper.py
More file actions
25 lines (21 loc) · 717 Bytes
/
Copy pathoper.py
File metadata and controls
25 lines (21 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from __future__ import annotations
from enum import Enum, auto
class OpId(Enum):
on = auto()
colon = auto()
not_colon = auto()
var = auto()
inv = auto()
left = auto()
right = auto()
halt = auto()
class Oper:
"""Operation class"""
def __init__(self, id: auto, args: list[UnionType[Oper, str]] = [], ops: list[Oper] = []) -> None:
self.id = id
self.args = args
self.ops = ops
def __str__(self) -> str:
return f"<Oper: id={self.id.name}" +\
(" args=\n" + str([str(i) for i in self.args]) if self.args else "\n") +\
(" ops=" + str([str(i) + "\n" for i in self.ops]) + ">" if self.ops else ">")