EvalEvaluator is called only if in root context. Added action and action_context to ExecutionContext

This commit is contained in:
2020-06-12 17:47:29 +02:00
parent c43a3ef946
commit 912455c343
27 changed files with 292 additions and 117 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ class AddConceptInSetEvaluator(OneReturnValueEvaluator):
True,
sheerka.new(BuiltinConcepts.USER_INPUT, body=parser_input, user_name="N/A"))
with context.push(desc=f"Recognizing '{name_node}'") as sub_context:
with context.push(BuiltinConcepts.PROCESS_INPUT, name_node, desc=f"Recognizing '{name_node}'") as sub_context:
r = sheerka.execute(sub_context, ret_val, ALL_STEPS)
one_r = core.builtin_helpers.expect_one(context, r)
sub_context.add_values(return_values=one_r)
+4 -3
View File
@@ -62,7 +62,8 @@ class ConceptEvaluator(OneReturnValueEvaluator):
evaluated,
parents=[return_value])
if not self.return_body or ConceptParts.BODY not in evaluated.compiled:
return sheerka.ret(self.name, True, evaluated, parents=[return_value])
else:
if self.return_body and ConceptParts.BODY in evaluated.compiled:
return sheerka.ret(self.name, True, evaluated.body, parents=[return_value])
else:
return sheerka.ret(self.name, True, evaluated, parents=[return_value])
+3 -1
View File
@@ -14,7 +14,9 @@ class EvalEvaluator(AllReturnValuesEvaluator):
super().__init__(self.NAME, [BuiltinConcepts.AFTER_EVALUATION], 80)
def matches(self, context, return_values):
return context.in_context(BuiltinConcepts.CONCEPT_VALUE_REQUESTED)
evaluation_parents = context.get_parents(lambda c: c.action == BuiltinConcepts.PROCESSING)
is_root = len(evaluation_parents) <= 1
return context.in_context(BuiltinConcepts.CONCEPT_VALUE_REQUESTED) and is_root
def eval(self, context, return_values):
sheerka = context.sheerka
+5 -1
View File
@@ -200,7 +200,11 @@ class PythonEvaluator(OneReturnValueEvaluator):
context.log(f"Concept {name} is already evaluated.", self.name)
else:
context.log(f"Evaluating '{concept}'", self.name)
with context.push(self.name, desc=f"Evaluating '{concept}'", obj=concept) as sub_context:
with context.push(BuiltinConcepts.EVALUATE_CONCEPT,
concept,
who=self.name,
desc=f"Evaluating '{concept}'",
obj=concept) as sub_context:
sub_context.local_hints.add(BuiltinConcepts.EVAL_BODY_REQUESTED)
evaluated = context.sheerka.evaluate_concept(sub_context, concept)
sub_context.add_values(return_values=evaluated)