Refactord Concept class to regroup all builtins properties into a ConceptMetadata class
This commit is contained in:
+18
-16
@@ -58,7 +58,7 @@ class SuccessConcept(Concept):
|
||||
|
||||
class ErrorConcept(Concept):
|
||||
def __init__(self, error=None):
|
||||
super().__init__(BuiltinConcepts.ERROR, True, False, BuiltinConcepts.ERROR, body=error)
|
||||
super().__init__(BuiltinConcepts.ERROR, True, False, BuiltinConcepts.ERROR, error)
|
||||
|
||||
def __repr__(self):
|
||||
return f"({self.id}){self.name}: {self.body}"
|
||||
@@ -71,10 +71,9 @@ class ReturnValueConcept(Concept):
|
||||
"""
|
||||
|
||||
def __init__(self, who=None, status=None, value=None, message=None, parents=None):
|
||||
super().__init__(BuiltinConcepts.RETURN_VALUE, True, False, BuiltinConcepts.RETURN_VALUE)
|
||||
super().__init__(BuiltinConcepts.RETURN_VALUE, True, False, BuiltinConcepts.RETURN_VALUE, value)
|
||||
self.set_prop("who", who)
|
||||
self.set_prop("status", status)
|
||||
self.body = value
|
||||
self.set_prop("message", message)
|
||||
self.set_prop("parents", parents)
|
||||
|
||||
@@ -100,7 +99,7 @@ class ReturnValueConcept(Concept):
|
||||
|
||||
@value.setter
|
||||
def value(self, value):
|
||||
self.body = value
|
||||
self.metadata.body = value
|
||||
|
||||
@property
|
||||
def message(self):
|
||||
@@ -140,9 +139,8 @@ class UnknownPropertyConcept(Concept):
|
||||
"""
|
||||
|
||||
def __init__(self, property_name=None, concept=None):
|
||||
super().__init__(BuiltinConcepts.UNKNOWN_PROPERTY, True, False, BuiltinConcepts.UNKNOWN_PROPERTY)
|
||||
super().__init__(BuiltinConcepts.UNKNOWN_PROPERTY, True, False, BuiltinConcepts.UNKNOWN_PROPERTY, property_name)
|
||||
self.set_prop("concept", concept)
|
||||
self.body = property_name
|
||||
|
||||
def __repr__(self):
|
||||
return f"UnknownProperty(property={self.property_name}, concept={self.concept})"
|
||||
@@ -162,11 +160,10 @@ class ParserResultConcept(Concept):
|
||||
"""
|
||||
|
||||
def __init__(self, parser=None, source=None, value=None, try_parsed=None):
|
||||
super().__init__(BuiltinConcepts.PARSER_RESULT, True, False, BuiltinConcepts.PARSER_RESULT)
|
||||
super().__init__(BuiltinConcepts.PARSER_RESULT, True, False, BuiltinConcepts.PARSER_RESULT, value)
|
||||
self.set_prop("parser", parser)
|
||||
self.set_prop("source", source)
|
||||
self.set_prop("try_parsed", try_parsed) # in case of error, what was found before the error
|
||||
self.body = value
|
||||
|
||||
def __repr__(self):
|
||||
return f"ParserResult({self.body})"
|
||||
@@ -205,9 +202,13 @@ class InvalidReturnValueConcept(Concept):
|
||||
"""
|
||||
|
||||
def __init__(self, return_value=None, evaluator=None):
|
||||
super().__init__(BuiltinConcepts.INVALID_RETURN_VALUE, True, False, BuiltinConcepts.INVALID_RETURN_VALUE)
|
||||
super().__init__(
|
||||
BuiltinConcepts.INVALID_RETURN_VALUE,
|
||||
True,
|
||||
False,
|
||||
BuiltinConcepts.INVALID_RETURN_VALUE,
|
||||
return_value)
|
||||
self.set_prop("evaluator", evaluator)
|
||||
self.body = return_value
|
||||
|
||||
|
||||
class BeforeParsingConcept(Concept):
|
||||
@@ -227,10 +228,13 @@ class AfterEvaluationConcept(Concept):
|
||||
|
||||
class PropertyEvalError(Concept):
|
||||
def __init__(self, property_name=None, concept=None, error=None):
|
||||
super().__init__(BuiltinConcepts.PROPERTY_EVAL_ERROR, True, False, BuiltinConcepts.PROPERTY_EVAL_ERROR)
|
||||
super().__init__(BuiltinConcepts.PROPERTY_EVAL_ERROR,
|
||||
True,
|
||||
False,
|
||||
BuiltinConcepts.PROPERTY_EVAL_ERROR,
|
||||
property_name)
|
||||
self.set_prop("concept", concept)
|
||||
self.set_prop("error", error)
|
||||
self.body = property_name
|
||||
|
||||
def __repr__(self):
|
||||
return f"PropertyEvalError(property={self.property_name}, concept={self.concept}), error={self.error})"
|
||||
@@ -250,8 +254,7 @@ class PropertyEvalError(Concept):
|
||||
|
||||
class EnumerationConcept(Concept):
|
||||
def __init__(self, iteration=None):
|
||||
super().__init__(BuiltinConcepts.ENUMERATION, True, False, BuiltinConcepts.ENUMERATION)
|
||||
self.body = iteration
|
||||
super().__init__(BuiltinConcepts.ENUMERATION, True, False, BuiltinConcepts.ENUMERATION, iteration)
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self.body)
|
||||
@@ -259,8 +262,7 @@ class EnumerationConcept(Concept):
|
||||
|
||||
class ListConcept(Concept):
|
||||
def __init__(self, items=None):
|
||||
super().__init__(BuiltinConcepts.LIST, True, False, BuiltinConcepts.LIST)
|
||||
self.body = items or []
|
||||
super().__init__(BuiltinConcepts.LIST, True, False, BuiltinConcepts.LIST, items or [])
|
||||
|
||||
def append(self, obj):
|
||||
self.body.append(obj)
|
||||
|
||||
Reference in New Issue
Block a user