I can manage infinite recursion when building concept
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
from core.builtin_concepts import ReturnValueConcept, BuiltinConcepts
|
||||
import ast
|
||||
|
||||
from core.builtin_concepts import ReturnValueConcept, BuiltinConcepts, ParserResultConcept
|
||||
from core.concept import Concept
|
||||
from evaluators.BaseEvaluator import BaseEvaluator
|
||||
from parsers.BaseParser import BaseParser
|
||||
from parsers.PythonParser import PythonNode
|
||||
|
||||
reduced_requested = ReturnValueConcept("Sheerka", True, Concept(name=BuiltinConcepts.REDUCE_REQUESTED,
|
||||
key=BuiltinConcepts.REDUCE_REQUESTED))
|
||||
@@ -12,7 +15,7 @@ def ret_val(value="value", who="who", status=True):
|
||||
|
||||
|
||||
def p_ret_val(value="value", parser="parser", status=True):
|
||||
return ReturnValueConcept(BaseParser.PREFIX + parser, status, value)
|
||||
return ReturnValueConcept(BaseParser.get_name(parser), status, value)
|
||||
|
||||
|
||||
def e_ret_val(value="value", evaluator="evaluator", status=True):
|
||||
@@ -40,6 +43,24 @@ def e_ret_val_new(key, evaluator="evaluator", status=True, **kwargs):
|
||||
return e_ret_val(body, evaluator, status)
|
||||
|
||||
|
||||
def pr_ret_val(value, parser="parser", source=None):
|
||||
"""
|
||||
ParserResult ReturnValue
|
||||
eg: ReturnValue with a ParserResult
|
||||
:param value:
|
||||
:param parser:
|
||||
:param source:
|
||||
:return:
|
||||
"""
|
||||
source = source or (value.name if isinstance(value, Concept) else "source")
|
||||
parser_result = ParserResultConcept(BaseParser.get_name(parser), source=source, value=value)
|
||||
return p_ret_val(parser_result, parser)
|
||||
|
||||
|
||||
def python_ret_val(source):
|
||||
python_node = PythonNode(source, ast.parse(source, f"<source>", 'eval'))
|
||||
return pr_ret_val(python_node, parser="Python", source=source)
|
||||
|
||||
def new_concept(key, **kwargs):
|
||||
res = Concept(key=key, name=key, is_builtin=False, is_unique=False)
|
||||
for k, v in kwargs.items():
|
||||
|
||||
Reference in New Issue
Block a user