Fixed parsing of BNF concepts mixed with isaset concepts
This commit is contained in:
@@ -5,7 +5,7 @@ import core.ast.nodes
|
||||
from core.ast.nodes import CallNodeConcept
|
||||
from core.ast.visitors import UnreferencedNamesVisitor
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.concept import Concept
|
||||
from core.concept import Concept, NotInit
|
||||
from parsers.BaseNodeParser import SourceCodeNode, ConceptNode, UnrecognizedTokensNode
|
||||
from parsers.BaseParser import BaseParser, ErrorNode
|
||||
|
||||
@@ -324,6 +324,11 @@ def ensure_evaluated(context, concept):
|
||||
if concept.metadata.is_evaluated:
|
||||
return concept
|
||||
|
||||
# do not try to evaluate concept that are not fully initialized
|
||||
for var in concept.metadata.variables:
|
||||
if var[0] not in concept.values or concept.get_value(var[0]) == NotInit:
|
||||
return concept
|
||||
|
||||
with context.push(BuiltinConcepts.EVALUATE_CONCEPT, concept, desc=f"Evaluating concept {concept}") as sub_context:
|
||||
sub_context.local_hints.add(BuiltinConcepts.EVAL_BODY_REQUESTED)
|
||||
evaluated = context.sheerka.evaluate_concept(sub_context, concept)
|
||||
|
||||
+12
-2
@@ -22,6 +22,16 @@ DEFINITION_TYPE_BNF = "bnf"
|
||||
DEFINITION_TYPE_DEF = "def"
|
||||
|
||||
|
||||
class NotInitialized:
|
||||
value = "**NotInit**"
|
||||
|
||||
def __repr__(self):
|
||||
return self.value
|
||||
|
||||
|
||||
NotInit = NotInitialized()
|
||||
|
||||
|
||||
class ConceptParts(Enum):
|
||||
"""
|
||||
Lists metadata that can contains some code
|
||||
@@ -51,7 +61,7 @@ class ConceptMetadata:
|
||||
desc: str # possible description for the concept
|
||||
id: str # unique identifier for a concept. The id will never be modified (but the key can)
|
||||
props: dict # hashmap of properties, values
|
||||
variables: list # list of concept variables, with their default values
|
||||
variables: list # list of concept variables(tuple), with their default values
|
||||
is_evaluated: bool = False # True is the concept is evaluated by sheerka.eval_concept()
|
||||
need_validation = False # True if the properties of the concept need to be validated
|
||||
full_serialization: bool = False # If True, the full object will be serialized, rather than just the diff
|
||||
@@ -183,7 +193,7 @@ class Concept:
|
||||
|
||||
self.metadata.variables.append((var_name, default_value))
|
||||
|
||||
self.set_value(var_name, None) # do not set the default value
|
||||
self.set_value(var_name, NotInit) # do not set the default value
|
||||
# why not setting variables to the default values ?
|
||||
# Because it may not be the real values, as metadata.variables need to be evaluated
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ from cache.Cache import Cache
|
||||
from cache.SetCache import SetCache
|
||||
from core.ast.nodes import python_to_concept
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.concept import Concept, ConceptParts, ensure_concept
|
||||
from core.concept import Concept, ConceptParts, ensure_concept, DEFINITION_TYPE_BNF
|
||||
from core.sheerka.services.sheerka_service import BaseService
|
||||
|
||||
GROUP_PREFIX = 'All_'
|
||||
@@ -145,10 +145,13 @@ class SheerkaSetsManager(BaseService):
|
||||
|
||||
return concepts
|
||||
|
||||
# already in cache ?
|
||||
if res := self.concepts_in_set.get(concept.id):
|
||||
return res
|
||||
|
||||
res = _get_set_elements(concept)
|
||||
|
||||
# put in cache
|
||||
self.concepts_in_set.put(concept.id, res)
|
||||
return res
|
||||
|
||||
@@ -196,6 +199,11 @@ class SheerkaSetsManager(BaseService):
|
||||
if not (isinstance(concept, Concept) and concept.id):
|
||||
return False
|
||||
|
||||
# KSI 29062020
|
||||
# To resolve infinite recursion between group concepts and BNF concepts
|
||||
if concept.metadata.definition_type == DEFINITION_TYPE_BNF:
|
||||
return False
|
||||
|
||||
# check if it has a group
|
||||
# TODO: use cache instead of directly requesting sdp
|
||||
if self.sets.get(concept.id):
|
||||
@@ -255,7 +263,8 @@ for x in xx__concepts__xx:
|
||||
for element_id in ids:
|
||||
concept = self.sheerka.get_by_id(element_id)
|
||||
if len(concept.metadata.variables) == 0:
|
||||
# only evaluate
|
||||
# The concepts are directly taken from Sheerka.get_by_id, so variable cannot be filled
|
||||
# It's the reason why we only evaluate concept with no variable
|
||||
evaluated = self.sheerka.evaluate_concept(sub_context, concept)
|
||||
if context.sheerka.is_success(evaluated):
|
||||
result.append(evaluated)
|
||||
|
||||
Reference in New Issue
Block a user