First implementation of questions management

This commit is contained in:
2020-08-14 08:16:33 +02:00
parent e84b394da2
commit 351c16f946
47 changed files with 1582 additions and 400 deletions
+16 -6
View File
@@ -18,10 +18,10 @@ class BuiltinConcepts(Enum):
# processing instructions during sheerka.execute()
EVAL_BODY_REQUESTED = "eval body" # to evaluate the body
EVAL_WHERE_REQUESTED = "eval where" # to evaluate the where clause
RETURN_VALUE_REQUESTED = "return value" # returns the body of the concept instead of the concept itself
RETURN_BODY_REQUESTED = "return body" # returns the body of the concept instead of the concept itself
REDUCE_REQUESTED = "reduce" # remove meaningless error when possible
EVAL_UNTIL_SUCCESS_REQUESTED = "eval until success" # PythonEvaluator tries combination until True is found
QUESTION_REQUESTED = "question" # a question is asked
EVAL_QUESTION_REQUESTED = "question" # the user input must be treated as question
# possible actions during sheerka.execute()
INIT_SHEERKA = "init sheerka" #
@@ -36,6 +36,7 @@ class BuiltinConcepts(Enum):
BEFORE_RENDERING = "before rendering" # activate before the output is rendered
RENDERING = "rendering" # rendering the response from sheerka
AFTER_RENDERING = "after rendering" # rendering the response from sheerka
EVALUATE_SOURCE = "evaluate source" #
EVALUATE_CONCEPT = "evaluate concept" # a concept will be evaluated
EVALUATING_CONCEPT = "evaluating concept" # a concept will be evaluated
EVALUATING_ATTRIBUTE = "evaluating concept attribute" #
@@ -45,7 +46,7 @@ class BuiltinConcepts(Enum):
INIT_BNF = "initialize bnf"
MANAGE_INFINITE_RECURSION = "manage infinite recursion"
PARSE_CODE = "execute source code"
EXEC_CODE = "execute source code"
EXEC_CODE = "execute source code" # to use when executing Python or other language compiled code
TESTING = "testing"
# builtin attributes
@@ -69,6 +70,7 @@ class BuiltinConcepts(Enum):
MULTIPLE_ERRORS = "multiple errors" # filter the result, only keep evaluator in error
NOT_FOR_ME = "not for me" # a parser recognize that the entry is not meant for it
IS_EMPTY = "is empty" # when a set is empty
NO_RESULT = "no result" # no return value returned
INVALID_RETURN_VALUE = "invalid return value" # the return value of an evaluator is not correct
CONCEPT_ALREADY_DEFINED = "concept already defined" # when you try to add the same concept twice
NOP = "no operation" # no operation concept. Does nothing
@@ -119,10 +121,10 @@ class BuiltinConcepts(Enum):
BuiltinUnique = [
BuiltinConcepts.EVAL_BODY_REQUESTED,
BuiltinConcepts.EVAL_WHERE_REQUESTED,
BuiltinConcepts.RETURN_VALUE_REQUESTED,
BuiltinConcepts.RETURN_BODY_REQUESTED,
BuiltinConcepts.REDUCE_REQUESTED,
BuiltinConcepts.EVAL_UNTIL_SUCCESS_REQUESTED,
BuiltinConcepts.QUESTION_REQUESTED,
BuiltinConcepts.EVAL_QUESTION_REQUESTED,
BuiltinConcepts.INIT_SHEERKA,
BuiltinConcepts.PROCESS_INPUT,
@@ -341,8 +343,11 @@ class ParserResultConcept(Concept):
if not isinstance(other, ParserResultConcept):
return False
self_parser_name = self.get_parser_name(self.parser)
other_parser_name = self.get_parser_name(other.parser)
return self.source == other.source and \
self.parser == other.parser and \
self_parser_name == other_parser_name and \
self.body == other.body and \
self.try_parsed == other.try_parsed
@@ -365,6 +370,11 @@ class ParserResultConcept(Concept):
def parser(self):
return self.get_value("parser")
@staticmethod
def get_parser_name(parser):
from parsers.BaseParser import BaseParser
return parser.name if isinstance(parser, BaseParser) else str(parser)
class InvalidReturnValueConcept(Concept):
"""