Fixed variable recognition when it is a concept
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -12,7 +12,7 @@ from core.rule import Rule
|
||||
from core.sheerka.ExecutionContext import ExecutionContext
|
||||
from core.tokenizer import Token, TokenKind
|
||||
from evaluators.BaseEvaluator import OneReturnValueEvaluator
|
||||
from parsers.PythonParser import PythonNode
|
||||
from parsers.PythonParser import PythonNode, get_python_node
|
||||
|
||||
TO_DISABLED = ["breakpoint", "callable", "compile", "delattr", "eval", "exec", "exit", "input", "locals", "open",
|
||||
"print", "quit", "setattr"]
|
||||
@@ -88,8 +88,7 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
|
||||
def eval(self, context, return_value):
|
||||
sheerka = context.sheerka
|
||||
node = return_value.value.value if isinstance(return_value.value.value, PythonNode) else \
|
||||
return_value.value.value.python_node
|
||||
node = get_python_node(return_value.value.value)
|
||||
|
||||
debugger = context.get_debugger(PythonEvaluator.NAME, "eval")
|
||||
debugger.debug_entering(node=node)
|
||||
|
||||
Reference in New Issue
Block a user