🐐 TEMPTA/CAPE
This commit is contained in:
@@ -1045,6 +1045,45 @@ class PerStatement(Node):
|
||||
return vtable, last_val
|
||||
|
||||
|
||||
class TemptaStatement(Node):
|
||||
def __init__(self, try_statements, error_var, catch_statements) -> None:
|
||||
self.try_statements = try_statements
|
||||
self.error_var = error_var
|
||||
self.catch_statements = catch_statements
|
||||
|
||||
def __eq__(self, other):
|
||||
return (type(self) == type(other)
|
||||
and self.try_statements == other.try_statements
|
||||
and self.error_var == other.error_var
|
||||
and self.catch_statements == other.catch_statements)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
try_stmts = f"try([{rep_join(self.try_statements)}])"
|
||||
catch_stmts = f"catch([{rep_join(self.catch_statements)}])"
|
||||
tempta_string = rep_join([try_stmts, repr(self.error_var), catch_stmts])
|
||||
return f"Tempta({tempta_string})"
|
||||
|
||||
def print(self):
|
||||
try_body = "\n".join(s.print() for s in self.try_statements)
|
||||
catch_body = "\n".join(s.print() for s in self.catch_statements)
|
||||
return f"TEMPTA {{\n{try_body}\n}} CAPE {self.error_var.print()} {{\n{catch_body}\n}}"
|
||||
|
||||
def _eval(self, vtable):
|
||||
last_val = ValNul()
|
||||
try:
|
||||
for statement in self.try_statements:
|
||||
vtable, last_val = statement.eval(vtable)
|
||||
if vtable["#return"] is not None or vtable["#break"] or vtable["#continue"]:
|
||||
return vtable, last_val
|
||||
except CentvrionError as e:
|
||||
vtable[self.error_var.name] = ValStr(str(e))
|
||||
for statement in self.catch_statements:
|
||||
vtable, last_val = statement.eval(vtable)
|
||||
if vtable["#return"] is not None or vtable["#break"] or vtable["#continue"]:
|
||||
return vtable, last_val
|
||||
return vtable, last_val
|
||||
|
||||
|
||||
class Invoca(Node):
|
||||
def __init__(self, callee, parameters) -> None:
|
||||
self.callee = callee
|
||||
|
||||
Reference in New Issue
Block a user