Managing concept properties in ConceptEvaluator

This commit is contained in:
2019-11-16 18:11:29 +01:00
parent 3a1dea19e8
commit 7fa509555d
13 changed files with 808 additions and 57 deletions
+11 -3
View File
@@ -13,8 +13,8 @@ class PythonEvaluator(OneReturnValueEvaluator):
def matches(self, context, return_value):
return return_value.status and \
isinstance(return_value.value, ParserResultConcept) and \
isinstance(return_value.value.value, PythonNode)
isinstance(return_value.value, ParserResultConcept) and \
isinstance(return_value.value.value, PythonNode)
def eval(self, context, return_value):
sheerka = context.sheerka
@@ -23,10 +23,18 @@ class PythonEvaluator(OneReturnValueEvaluator):
try:
log.debug(f"Evaluating python node {node}")
compiled = compile(node.ast_, "<string>", "eval")
evaluated = eval(compiled, {}, {"sheerka": context.sheerka})
evaluated = eval(compiled, {}, self.get_locals(context))
return sheerka.ret(self.name, True, evaluated, parents=[return_value])
except Exception as error:
error = sheerka.new(BuiltinConcepts.ERROR, body=error)
return sheerka.ret(self.name, False, error, parents=[return_value])
else:
return sheerka.ret(self.name, False, sheerka.new(BuiltinConcepts.ERROR), parents=[return_value])
@staticmethod
def get_locals(context):
my_locals = {"sheerka": context.sheerka}
if context.obj:
for prop_name, prop_value in context.obj.props.items():
my_locals[prop_name] = prop_value.value
return my_locals