Added RET keyword
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.builtin_helpers import ensure_evaluated
|
||||
from core.concept import Concept, ConceptParts
|
||||
from evaluators.BaseEvaluator import OneReturnValueEvaluator
|
||||
|
||||
|
||||
class RetEvaluator(OneReturnValueEvaluator):
|
||||
"""
|
||||
The evaluator transform the a concept, using the ret value
|
||||
"""
|
||||
|
||||
NAME = "Ret"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(self.NAME, [BuiltinConcepts.EVALUATION], 10)
|
||||
|
||||
def matches(self, context, return_value):
|
||||
return return_value.status and \
|
||||
isinstance(return_value.value, Concept) and \
|
||||
return_value.value.metadata.ret is not None
|
||||
|
||||
def eval(self, context, return_value):
|
||||
sheerka = context.sheerka
|
||||
concept = return_value.value
|
||||
context.log(f"Processing ret value for concept {concept}.", self.name)
|
||||
|
||||
if not concept.metadata.is_evaluated:
|
||||
evaluated = ensure_evaluated(context, concept)
|
||||
if evaluated.key != concept.key:
|
||||
context.log(f"Failed to evaluate concept '{concept}'")
|
||||
return None
|
||||
ret = evaluated.get_value(ConceptParts.RET)
|
||||
else:
|
||||
ret = concept.get_value(ConceptParts.RET)
|
||||
|
||||
if isinstance(ret, Concept) and sheerka.is_known(ret):
|
||||
return sheerka.ret(self.name, True, ret, parents=[return_value])
|
||||
|
||||
context.log(f"ret '{ret}' is not a concept!")
|
||||
return None
|
||||
Reference in New Issue
Block a user