First implementation of questions management
This commit is contained in:
@@ -1,14 +1,11 @@
|
||||
from core.ast.nodes import python_to_concept
|
||||
import core.utils
|
||||
from core.builtin_concepts import ParserResultConcept, ReturnValueConcept, BuiltinConcepts
|
||||
from core.builtin_helpers import get_names
|
||||
from core.concept import Concept, DEFINITION_TYPE_BNF, DEFINITION_TYPE_DEF
|
||||
from core.tokenizer import TokenKind, Tokenizer
|
||||
from evaluators.BaseEvaluator import OneReturnValueEvaluator
|
||||
from parsers.BaseParser import NotInitializedNode
|
||||
from parsers.BnfNodeParser import ParsingExpression, ParsingExpressionVisitor
|
||||
from parsers.DefaultParser import DefConceptNode, NameNode
|
||||
from parsers.PythonParser import PythonNode
|
||||
import core.utils
|
||||
|
||||
|
||||
class ConceptOrRuleNameVisitor(ParsingExpressionVisitor):
|
||||
@@ -132,30 +129,6 @@ class AddConceptEvaluator(OneReturnValueEvaluator):
|
||||
variables = filter(lambda x: x in concept_name, names)
|
||||
return set(variables)
|
||||
|
||||
#
|
||||
# Case of python code
|
||||
#
|
||||
if isinstance(ret_value.value, ParserResultConcept) and isinstance(ret_value.value.value, PythonNode):
|
||||
if len(concept_name) > 1:
|
||||
# tokens from ParserResult or source from python node
|
||||
variables = set()
|
||||
tokens = ret_value.value.tokens or list(Tokenizer(ret_value.value.value.source))
|
||||
tokens = [t.str_value for t in tokens]
|
||||
for identifier in [i for i in concept_name if str(i).isalnum()]:
|
||||
if identifier in tokens:
|
||||
variables.add(identifier)
|
||||
# python_node = ret_value.value.value
|
||||
# as_concept_node = python_to_concept(python_node.ast_)
|
||||
# names = get_names(sheerka, as_concept_node)
|
||||
# variables = filter(lambda x: x in concept_name, names)
|
||||
return variables
|
||||
|
||||
#
|
||||
# case of concept
|
||||
#
|
||||
if isinstance(ret_value.value, ParserResultConcept) and isinstance(ret_value.value.value, Concept):
|
||||
return set(ret_value.value.value.values.keys())
|
||||
|
||||
#
|
||||
# case of BNF
|
||||
#
|
||||
@@ -164,4 +137,16 @@ class AddConceptEvaluator(OneReturnValueEvaluator):
|
||||
visitor.visit(ret_value.value.value)
|
||||
return set(visitor.names)
|
||||
|
||||
#
|
||||
# other (python code and concept)
|
||||
#
|
||||
if isinstance(ret_value.value, ParserResultConcept) and len(concept_name) > 1:
|
||||
variables = set()
|
||||
tokens = ret_value.value.tokens or list(Tokenizer(ret_value.value.source, yield_eof=False))
|
||||
tokens = [t.str_value for t in tokens]
|
||||
for identifier in [i for i in concept_name if str(i).isalnum()]:
|
||||
if identifier in tokens:
|
||||
variables.add(identifier)
|
||||
return variables
|
||||
|
||||
return []
|
||||
|
||||
Reference in New Issue
Block a user