Enforce checking function and method names if they're exist before creating new ones

This commit is contained in:
Bartłomiej Pluta
2019-07-08 22:53:32 +02:00
parent d4b4aa48ee
commit a3dfae73f1
5 changed files with 39 additions and 12 deletions

View File

@@ -1,6 +1,7 @@
from smnp.ast.node.none import NoneNode
from smnp.ast.node.ret import ReturnNode
from smnp.ast.node.variable import TypedVariableNode
from smnp.error.runtime import RuntimeException
from smnp.library.signature import signature, listOfMatchers, ofType
from smnp.runtime.evaluator import Evaluator, evaluate
from smnp.runtime.evaluators.expression import expressionEvaluator
@@ -21,11 +22,15 @@ class FunctionDefinitionEvaluator(Evaluator):
@classmethod
def evaluator(cls, node, environment):
name = node.name.value
signature = argumentsNodeToMethodSignature(node.arguments)
arguments = [ arg.variable.value for arg in node.arguments ]
body = node.body
environment.addCustomFunction(name, signature, arguments, body)
try:
name = node.name.value
signature = argumentsNodeToMethodSignature(node.arguments)
arguments = [ arg.variable.value for arg in node.arguments ]
body = node.body
environment.addCustomFunction(name, signature, arguments, body)
except RuntimeException as e:
e.pos = node.pos
raise e
def argumentsNodeToMethodSignature(node):