Refactord Concept class to regroup all builtins properties into a ConceptMetadata class

This commit is contained in:
2019-11-30 18:16:20 +01:00
parent 5e539a4b28
commit 75c8793d53
13 changed files with 186 additions and 147 deletions
+1 -1
View File
@@ -40,7 +40,7 @@ class AddConceptEvaluator(OneReturnValueEvaluator):
# update the parts
source = self.get_source(part_ret_val)
setattr(concept, prop, source)
setattr(concept.metadata, prop, source)
# try to find what can be a property
for p in self.get_props(part_ret_val):
+5 -5
View File
@@ -29,8 +29,8 @@ class ConceptEvaluator(OneReturnValueEvaluator):
# pre condition should already be validated by the parser.
# It's a mandatory condition for the concept before it can be recognized
if len(concept.codes) == 0:
sheerka.add_codes_to_concept(context, concept)
if len(concept.cached_asts) == 0:
sheerka.initialize_concept_asts(context, concept)
# TODO; check pre
# if pre is not true, return Concept with a false value
@@ -38,7 +38,7 @@ class ConceptEvaluator(OneReturnValueEvaluator):
# Evaluate the properties
for prop in concept.props:
sub_context = context.push(self.name, f"Evaluating property '{prop}'", concept)
res = self.evaluate_parsing(sheerka, sub_context, concept.codes[prop])
res = self.evaluate_parsing(sheerka, sub_context, concept.cached_asts[prop])
if res.status:
concept.set_prop(prop, res.value)
else:
@@ -49,11 +49,11 @@ class ConceptEvaluator(OneReturnValueEvaluator):
parents=[return_value])
# Returns the concept when no body
if ConceptParts.BODY not in concept.codes:
if ConceptParts.BODY not in concept.cached_asts:
return sheerka.ret(self.name, True, concept, parents=[return_value])
# Evaluate the body otherwise
body = concept.codes[ConceptParts.BODY]
body = concept.cached_asts[ConceptParts.BODY]
if body is None:
raise NotImplementedError("Seems weird !")
+1 -1
View File
@@ -40,5 +40,5 @@ class DuplicateConceptEvaluator(AllReturnValuesEvaluator):
return sheerka.ret(
self.name,
False,
sheerka.new(BuiltinConcepts.CONCEPT_ALREADY_DEFINED, obj=self.already_defined),
sheerka.new(BuiltinConcepts.CONCEPT_ALREADY_DEFINED, body=self.already_defined),
parents=return_values)
+1 -1
View File
@@ -48,7 +48,7 @@ class TooManySuccessEvaluator(AllReturnValuesEvaluator):
def eval(self, context, return_values):
sheerka = context.sheerka
if not core.builtin_helpers.is_same_success(sheerka, self.success):
too_many_success = sheerka.new(BuiltinConcepts.TOO_MANY_SUCCESS, obj=self.success)
too_many_success = sheerka.new(BuiltinConcepts.TOO_MANY_SUCCESS, body=self.success)
return sheerka.ret(self.name, False, too_many_success, parents=return_values)
return None