Fixed #125: SheerkaErrorManager

Fixed #135: Change services service priorities
Fixed #136: ErrorManager: Implement recognize_error
Fixed #137: BNFNodeParser : Error when parsing regex with sub parsers
Fixed #138: get_last_errors(): real errors sources are lost
Fixed #139: OneError return value removes the origin of the error
Fixed #140: Concept variables are not correctly handled when parsing sub expression
Fixed #143: Implement has_unknown_concepts()
This commit is contained in:
2021-10-28 14:04:41 +02:00
parent 48ab72fd9c
commit 87cab44fb8
56 changed files with 1391 additions and 1286 deletions
+27 -1
View File
@@ -6,7 +6,7 @@ from core.ast_helpers import UnreferencedVariablesVisitor
from core.builtin_concepts import ReturnValueConcept
from core.builtin_concepts_ids import BuiltinConcepts
from core.concept import AllConceptParts, Concept
from core.global_symbols import ErrorObj, NotFound, NotInit, SyaAssociativity
from core.global_symbols import ErrorItem, ErrorObj, NotFound, NotInit, SyaAssociativity
from core.rule import Rule
from core.sheerka.ExecutionContext import ExecutionContext
from core.sheerka.services.SheerkaAdmin import SheerkaAdmin
@@ -110,8 +110,14 @@ sheerka_globals = {
"get_type": get_type,
"hasattr": sheerka_hasattr,
"getattr": sheerka_getattr,
"ErrorItem": ErrorItem
}
# Adds all concepts that have their own class definition
for c in core.utils.get_classes("core.builtin_concepts"):
if issubclass(c, Concept) and c != Concept:
sheerka_globals[c.__name__] = c
def inject_context(context):
"""
@@ -285,6 +291,7 @@ def get_variables_from_concept_asts(context, concept, known_variables, parameter
"""
From a given concept that is already compiled,
browse the compiled to see if there is any symbol that is unknown, eg variable
It is used to detect all mandatory variables before concept evaluation
:param context:
:param concept:
:param known_variables:
@@ -348,6 +355,25 @@ def get_variables_from_concept_asts(context, concept, known_variables, parameter
return variables
def get_possible_variables_from_concept(context, concept):
"""
Given a concept, get its symbols that may be considered as variables for other concepts
:param context:
:param concept:
:return:
"""
possible_variables = set(concept.get_metadata().parameters)
core.builtin_helpers.ensure_bnf(context, concept)
if concept.get_bnf():
from parsers.BnfNodeParser import BnfNodeConceptExpressionVisitor
visitor = BnfNodeConceptExpressionVisitor()
visitor.visit(concept.get_bnf())
possible_variables.update([c.name if isinstance(c, Concept) else c for c in visitor.references])
return possible_variables
def is_variable(context, name):
"""
tells whether or not the name can be a variable