Refactored Concept class for better separation of metadata, compiled and values
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ class ConceptsWithConceptsParser(BaseParser):
|
||||
|
||||
if isinstance(node, ConceptNode):
|
||||
prop_name = list(concept.props.keys())[index]
|
||||
concept.cached_asts[prop_name] = node.concept
|
||||
concept.compiled[prop_name] = node.concept
|
||||
context.log(
|
||||
self.verbose_log,
|
||||
f"Setting property '{prop_name}='{node.concept}'.",
|
||||
@@ -64,7 +64,7 @@ class ConceptsWithConceptsParser(BaseParser):
|
||||
prop_name = list(concept.props.keys())[index]
|
||||
sheerka = context.sheerka
|
||||
value = sheerka.new(BuiltinConcepts.PARSER_RESULT, parser=self, source=node.source, body=node.node)
|
||||
concept.cached_asts[prop_name] = [context.sheerka.ret(self.name, True, value)]
|
||||
concept.compiled[prop_name] = [context.sheerka.ret(self.name, True, value)]
|
||||
context.log(
|
||||
self.verbose_log,
|
||||
f"Setting property '{prop_name}'='Python({node.source})'.",
|
||||
|
||||
@@ -55,7 +55,7 @@ class ExactConceptParser(BaseParser):
|
||||
for i, token in enumerate(combination):
|
||||
if token.startswith(VARIABLE_PREFIX):
|
||||
index = int(token[len(VARIABLE_PREFIX):])
|
||||
concept.set_prop_by_index(index, words[i])
|
||||
concept.def_prop_by_index(index, words[i])
|
||||
if self.verbose_log.isEnabledFor(logging.DEBUG):
|
||||
prop_name = list(concept.props.keys())[index]
|
||||
context.log(
|
||||
|
||||
Reference in New Issue
Block a user