Fixed variable recognition when it is a concept

This commit is contained in:
2020-11-20 17:24:52 +01:00
parent 315f8ea09b
commit 0e945fe0fd
8 changed files with 79 additions and 36 deletions
+7 -9
View File
@@ -8,7 +8,7 @@ from evaluators.BaseEvaluator import OneReturnValueEvaluator
from parsers.BaseParser import NotInitializedNode
from parsers.BnfNodeParser import ParsingExpression, ParsingExpressionVisitor
from parsers.DefConceptParser import DefConceptNode, NameNode
from parsers.PythonParser import PythonNode
from parsers.PythonParser import PythonNode, get_python_node
class ConceptOrRuleNameVisitor(ParsingExpressionVisitor):
@@ -129,15 +129,13 @@ class DefConceptEvaluator(OneReturnValueEvaluator):
This function can only be a draft, as there may be tons of different situations
I guess that it can only be complete when will we have access to Sheerka memory
"""
#
# Case of NameNode
#
if isinstance(ret_value, NameNode):
names = [str(t.value) for t in ret_value.tokens if t.type in (
TokenKind.IDENTIFIER, TokenKind.STRING, TokenKind.KEYWORD)]
variables = filter(lambda x: x in concept_name, names)
return set(variables)
return set(filter(lambda x: x in concept_name and context.sheerka.not_is_variable(x), names))
#
# case of BNF
@@ -150,13 +148,13 @@ class DefConceptEvaluator(OneReturnValueEvaluator):
#
# Case of python code
#
if isinstance(ret_value.value, ParserResultConcept) and isinstance(ret_value.value.value, PythonNode):
if (python_node := get_python_node(ret_value.value.value)) is not None:
if len(concept_name) > 1:
python_node = ret_value.value.value
visitor = UnreferencedVariablesVisitor(context)
names = visitor.get_names(python_node.ast_)
variables = filter(lambda x: x in concept_name, names)
return set(variables)
return set(filter(lambda x: x in concept_name and context.sheerka.not_is_variable(x), names))
else:
return set()
#
# Concept
@@ -172,4 +170,4 @@ class DefConceptEvaluator(OneReturnValueEvaluator):
variables.add(identifier)
return variables
return []
return set()