Concept validation must be requested

This commit is contained in:
2020-03-09 12:23:53 +01:00
parent ef31a4807d
commit 1bde97b5e3
27 changed files with 346 additions and 280 deletions
+11 -13
View File
@@ -15,19 +15,17 @@ class ConceptEvaluator(OneReturnValueEvaluator):
def __init__(self, return_body=False):
super().__init__(self.NAME, [BuiltinConcepts.EVALUATION], 50)
self.return_body = return_body
self.evaluate_body = False
self.is_initialized = False
def init_evaluator(self, context, return_values):
if BuiltinConcepts.CONCEPT_EVAL_REQUESTED in context.extra_info:
self.evaluate_body = True
for r in return_values:
if r.status and context.sheerka.isinstance(r.body, BuiltinConcepts.CONCEPT_VALUE_REQUESTED):
self.evaluate_body = True
break
self.is_initialized = True
# def init_evaluator(self, context, return_values):
# if BuiltinConcepts.EVAL_BODY_REQUESTED in context.local_hints:
# self.evaluate_body = True
#
# for r in return_values:
# if r.status and context.sheerka.isinstance(r.body, BuiltinConcepts.CONCEPT_VALUE_REQUESTED):
# self.evaluate_body = True
# break
#
# self.is_initialized = True
def matches(self, context, return_value):
return return_value.status and \
@@ -49,7 +47,7 @@ class ConceptEvaluator(OneReturnValueEvaluator):
return sheerka.ret(self.name, True, value, parents=[return_value])
evaluated = sheerka.evaluate_concept(context, concept, self.evaluate_body)
evaluated = sheerka.evaluate_concept(context, concept)
if evaluated.key != concept.key:
# evaluated.key != concept.key means that we have transformed the concept
+5 -18
View File
@@ -12,16 +12,9 @@ class EvalEvaluator(AllReturnValuesEvaluator):
def __init__(self):
super().__init__(self.NAME, [BuiltinConcepts.AFTER_EVALUATION], 80)
self.eval_requested = None
def matches(self, context, return_values):
sheerka = context.sheerka
for ret in return_values:
if ret.status and sheerka.isinstance(ret.body, BuiltinConcepts.CONCEPT_VALUE_REQUESTED):
self.eval_requested = ret
return True
return False
return context.in_context(BuiltinConcepts.CONCEPT_VALUE_REQUESTED)
def eval(self, context, return_values):
sheerka = context.sheerka
@@ -30,22 +23,16 @@ class EvalEvaluator(AllReturnValuesEvaluator):
for ret_val in return_values:
if ret_val.status and isinstance(ret_val.body, Concept) and ret_val.body.body:
context.log(f"Evaluating {ret_val.body}", who=self)
result.append(sheerka.ret(self.name, True, ret_val.body.body, parents=[ret_val, self.eval_requested]))
result.append(sheerka.ret(self.name, True, ret_val.body.body, parents=[ret_val]))
elif ret_val.status and sheerka.isaset(context, ret_val.body):
context.log(f"Evaluating set {ret_val.body}", who=self)
result.append(sheerka.ret(
self.name,
True,
sheerka.get_set_elements(context, ret_val.body),
parents=[ret_val, self.eval_requested]))
parents=[ret_val]))
if len(result) > 0:
return result
else:
# suppress the successful BuiltinConcepts.CONCEPT_EVAL_REQUESTED
# status of CONCEPT_EVAL_REQUESTED is now set to False
return sheerka.ret(
self.name,
False,
sheerka.new(BuiltinConcepts.CONCEPT_VALUE_REQUESTED),
parents=[self.eval_requested])
return None
+3 -4
View File
@@ -33,8 +33,7 @@ class PrepareEvalEvaluator(OneReturnValueEvaluator):
self.name,
True, sheerka.new(BuiltinConcepts.USER_INPUT, body=self.text[5:], user_name=context.event.user))
evaluation_requested = sheerka.ret(
self.name,
True, sheerka.new(BuiltinConcepts.CONCEPT_VALUE_REQUESTED))
context.global_hints.add(BuiltinConcepts.EVAL_BODY_REQUESTED)
context.global_hints.add(BuiltinConcepts.CONCEPT_VALUE_REQUESTED)
return [new_text_to_parse, evaluation_requested]
return new_text_to_parse
+2 -1
View File
@@ -112,7 +112,8 @@ class PythonEvaluator(OneReturnValueEvaluator):
context.log(f"Evaluating '{concept}'", self.name)
with context.push(self.name, desc=f"Evaluating '{concept}'", obj=concept) as sub_context:
evaluated = context.sheerka.evaluate_concept(sub_context, concept, True)
sub_context.local_hints.add(BuiltinConcepts.EVAL_BODY_REQUESTED)
evaluated = context.sheerka.evaluate_concept(sub_context, concept)
sub_context.add_values(return_values=evaluated)
if evaluated.key == concept.key: