Refactored to use cached_asts in Concepts, rather than setting up a value directly
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
from dataclasses import field, dataclass
|
||||
from collections import defaultdict
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.concept import Concept
|
||||
from core.concept import Concept, ConceptParts, DoNotResolve
|
||||
from core.tokenizer import TokenKind, Tokenizer, Token
|
||||
from parsers.BaseParser import BaseParser, Node, ErrorNode
|
||||
import core.utils
|
||||
@@ -702,6 +702,9 @@ class ConceptLexerParser(BaseParser):
|
||||
else:
|
||||
to_match = node.concept
|
||||
|
||||
if to_match not in self.concepts_grammars:
|
||||
return False
|
||||
|
||||
return _is_infinite_recursion(ref_concept, self.concepts_grammars[to_match])
|
||||
|
||||
if isinstance(node, OrderedChoice):
|
||||
@@ -847,17 +850,17 @@ class ConceptLexerParser(BaseParser):
|
||||
Adds a new entry,
|
||||
makes a list if the property already exists
|
||||
"""
|
||||
if prop_name not in _concept.props or _concept.props[prop_name].value is None:
|
||||
if prop_name not in _concept.cached_asts or _concept.cached_asts[prop_name] is None:
|
||||
# new entry
|
||||
_concept.set_prop(prop_name, value)
|
||||
_concept.cached_asts[prop_name] = value
|
||||
else:
|
||||
# make a list if there was a value
|
||||
previous_value = _concept.props[prop_name].value
|
||||
previous_value = _concept.cached_asts[prop_name]
|
||||
if isinstance(previous_value, list):
|
||||
previous_value.append(value)
|
||||
else:
|
||||
new_value = [previous_value, value]
|
||||
_concept.set_prop(prop_name, new_value)
|
||||
_concept.cached_asts[prop_name] = new_value
|
||||
|
||||
def _look_for_concept_match(_underlying):
|
||||
if isinstance(_underlying.parsing_expression, ConceptMatch):
|
||||
@@ -881,7 +884,7 @@ class ConceptLexerParser(BaseParser):
|
||||
result = self.finalize_concept(sheerka, ref_tpl, concept_match_node.children[0], init_empty_body)
|
||||
_underlying_value_cache[id(concept_match_node)] = result
|
||||
else:
|
||||
result = _underlying.source
|
||||
result = DoNotResolve(_underlying.source)
|
||||
|
||||
return result
|
||||
|
||||
@@ -898,8 +901,7 @@ class ConceptLexerParser(BaseParser):
|
||||
concept = sheerka.new(key)
|
||||
if init_empty_body and concept.body is None:
|
||||
value = _get_underlying_value(underlying)
|
||||
concept.metadata.body = value
|
||||
concept.metadata.is_evaluated = True
|
||||
concept.cached_asts[ConceptParts.BODY] = value
|
||||
if underlying.parsing_expression.rule_name:
|
||||
_add_prop(concept, underlying.parsing_expression.rule_name, value)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user