Fixed some misbehaviours regarding question() + added #import functionality when restoring
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import core.utils
|
||||
from core.ast.nodes import python_to_concept
|
||||
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.sheerka.services.SheerkaExecute import ParserInput
|
||||
from core.tokenizer import TokenKind, Tokenizer
|
||||
@@ -7,6 +9,7 @@ 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
|
||||
|
||||
|
||||
class ConceptOrRuleNameVisitor(ParsingExpressionVisitor):
|
||||
@@ -141,7 +144,18 @@ class AddConceptEvaluator(OneReturnValueEvaluator):
|
||||
return set(visitor.names)
|
||||
|
||||
#
|
||||
# other (python code and concept)
|
||||
# Case of python code
|
||||
#
|
||||
if isinstance(ret_value.value, ParserResultConcept) and isinstance(ret_value.value.value, PythonNode):
|
||||
if len(concept_name) > 1:
|
||||
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 set(variables)
|
||||
|
||||
#
|
||||
# Concept
|
||||
#
|
||||
if isinstance(ret_value.value, ParserResultConcept) and len(concept_name) > 1:
|
||||
variables = set()
|
||||
|
||||
@@ -26,7 +26,8 @@ class PostExecutionEvaluator(OneReturnValueEvaluator):
|
||||
|
||||
def eval(self, context, return_value):
|
||||
# only support the rule for the COMMANDS
|
||||
body = return_value.body.body
|
||||
#body = return_value.body.body
|
||||
body = context.sheerka.objvalue(return_value)
|
||||
return context.sheerka.ret(
|
||||
self.name,
|
||||
True,
|
||||
|
||||
@@ -36,10 +36,12 @@ class PrepareEvalQuestionEvaluator(OneReturnValueEvaluator):
|
||||
self.name,
|
||||
True, sheerka.new(BuiltinConcepts.USER_INPUT, body=self.question, user_name=context.event.user_id))
|
||||
|
||||
root = context.get_parents(lambda ec: ec.action == BuiltinConcepts.PROCESS_INPUT)
|
||||
root = context.get_parents(lambda ec: ec.action in (BuiltinConcepts.EVALUATING_CONCEPT,
|
||||
BuiltinConcepts.PROCESS_INPUT))
|
||||
root = root[0] if root else context
|
||||
root.protected_hints.add(BuiltinConcepts.EVAL_QUESTION_REQUESTED)
|
||||
root.protected_hints.add(BuiltinConcepts.EVAL_BODY_REQUESTED)
|
||||
root.protected_hints.add(BuiltinConcepts.RETURN_BODY_REQUESTED)
|
||||
root.add_to_protected_hints(BuiltinConcepts.EVAL_QUESTION_REQUESTED)
|
||||
root.add_to_protected_hints(BuiltinConcepts.EVAL_UNTIL_SUCCESS_REQUESTED)
|
||||
root.add_to_protected_hints(BuiltinConcepts.EVAL_BODY_REQUESTED)
|
||||
root.add_to_protected_hints(BuiltinConcepts.RETURN_BODY_REQUESTED)
|
||||
|
||||
return new_text_to_parse
|
||||
|
||||
Reference in New Issue
Block a user