Refactored Concept class for better separation of metadata, compiled and values

This commit is contained in:
2020-01-17 17:27:54 +01:00
parent 3789ef25d1
commit a7b239c167
27 changed files with 614 additions and 349 deletions
+6 -6
View File
@@ -864,17 +864,17 @@ class ConceptLexerParser(BaseParser):
Adds a new entry,
makes a list if the property already exists
"""
if prop_name not in _concept.cached_asts or _concept.cached_asts[prop_name] is None:
if prop_name not in _concept.compiled or _concept.compiled[prop_name] is None:
# new entry
_concept.cached_asts[prop_name] = value
_concept.compiled[prop_name] = value
else:
# make a list if there was a value
previous_value = _concept.cached_asts[prop_name]
previous_value = _concept.compiled[prop_name]
if isinstance(previous_value, list):
previous_value.append(value)
else:
new_value = [previous_value, value]
_concept.cached_asts[prop_name] = new_value
_concept.compiled[prop_name] = new_value
def _look_for_concept_match(_underlying):
if isinstance(_underlying.parsing_expression, ConceptExpression):
@@ -913,9 +913,9 @@ class ConceptLexerParser(BaseParser):
key = (template.key, template.id) if template.id else template.key
concept = sheerka.new(key)
if init_empty_body and concept.body is None:
if init_empty_body and concept.metadata.body is None:
value = _get_underlying_value(underlying)
concept.cached_asts[ConceptParts.BODY] = value
concept.compiled[ConceptParts.BODY] = value
if underlying.parsing_expression.rule_name:
_add_prop(concept, underlying.parsing_expression.rule_name, value)