Reformat evaluator #1

This commit is contained in:
Bartłomiej Pluta
2019-07-04 17:57:12 +02:00
parent f0cbf37fe9
commit 34a0eda199
36 changed files with 470 additions and 270 deletions

View File

@@ -36,8 +36,8 @@ class Environment():
return value
else:
return value
raise RuntimeException(pos, f"Variable '{name}' is not declared" + (
"" if type is None else f" (expected type: {type})"))
raise RuntimeException(f"Variable '{name}' is not declared" + (
"" if type is None else f" (expected type: {type})"), pos)
def findVariableScope(self, name, type=None):
for scope in reversed(self.scopes):
@@ -46,4 +46,20 @@ class Environment():
if isinstance(scope[name], type):
return scope
else:
return scope
return scope
def scopesToString(self):
return "Scopes:\n" + ("\n".join([ f" [{i}]: {scope}" for i, scope in enumerate(self.scopes) ]))
def functionsToString(self):
return "Functions:\n" + ("\n".join([ f" {function.name}(...)" for function in self.functions ]))
def methodsToString(self):
return "Methods:\n" + ("\n".join([f" {function.name}(...)" for function in self.methods]))
def __str__(self):
return self.scopesToString() + self.functionsToString() + self.methodsToString()
def __repr__(self):
return self.__str__()