Fixed #29: Parsers: Implement parsing memoization
Fixed #77 : Parser: ShortTermMemoryParser should be called separately Fixed #78 : Remove VariableNode usage Fixed #79 : ConceptManager: Implement compile caching Fixed #80 : SheerkaExecute : parsers_key is not correctly computed Fixed #81 : ValidateConceptEvaluator : Validate concept's where and pre clauses right after the parsing Fixed #82 : SheerkaIsAManager: isa() failed when the set as a body Fixed #83 : ValidateConceptEvaluator : Support BNF and SYA Concepts Fixed #84 : ExpressionParser: Implement the parser as a standard parser Fixed #85 : Services: Give order to services Fixed #86 : cannot manage smart_get_attr(the short, color)
This commit is contained in:
@@ -4,6 +4,13 @@ import core.builtin_helpers
|
||||
from core.builtin_concepts import ReturnValueConcept, BuiltinConcepts
|
||||
from core.concept import Concept
|
||||
from core.global_symbols import NotInit
|
||||
from core.sheerka.services.SheerkaExecute import ParserInput
|
||||
from core.tokenizer import Tokenizer
|
||||
from evaluators.BaseEvaluator import BaseEvaluator
|
||||
from evaluators.ValidateConceptEvaluator import ValidateConceptEvaluator
|
||||
from parsers.BaseNodeParser import ConceptNode
|
||||
from parsers.BaseParser import BaseParser
|
||||
from parsers.SyaNodeParser import SyaNodeParser
|
||||
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
||||
|
||||
|
||||
@@ -162,6 +169,7 @@ class TestBuiltinHelpers(TestUsingMemoryBasedSheerka):
|
||||
(" is_question ( ) ", True),
|
||||
("context.in_context(BuiltinConcepts.EVAL_QUESTION_REQUESTED)", True),
|
||||
(" context . in_context ( BuiltinConcepts . EVAL_QUESTION_REQUESTED ) ", True),
|
||||
("in_context(BuiltinConcepts.EVAL_QUESTION_REQUESTED)", True),
|
||||
(None, False),
|
||||
("", False),
|
||||
(NotInit, False),
|
||||
@@ -193,6 +201,58 @@ class TestBuiltinHelpers(TestUsingMemoryBasedSheerka):
|
||||
evaluated = [r for r in res if r.status][0].body
|
||||
assert evaluated.body is NotInit
|
||||
|
||||
def test_i_can_evaluate_from_source_with_specific_evaluators(self):
|
||||
sheerka, context, one = self.init_concepts(Concept("foo", body="'hello world'"))
|
||||
|
||||
res = core.builtin_helpers.evaluate_from_source(context, "foo", eval_body=True, evaluators=["Python"])
|
||||
res = self.successful_return_values(res)
|
||||
assert len(res) == 1
|
||||
assert res[0].who.startswith(BaseParser.PREFIX) # Cannot evaluate concept with PythonEvaluator
|
||||
|
||||
res = core.builtin_helpers.evaluate_from_source(context, "foo", eval_body=True, evaluators=["Concept"])
|
||||
res = self.successful_return_values(res)
|
||||
assert len(res) == 1
|
||||
assert res[0].who == BaseEvaluator.PREFIX + "Concept"
|
||||
assert sheerka.isinstance(res[0].body.body,
|
||||
BuiltinConcepts.PARSER_RESULT) # cannot eval 'hello world' without PythonEvaluator
|
||||
|
||||
res = core.builtin_helpers.evaluate_from_source(context, "foo", eval_body=True,
|
||||
evaluators=["Concept", "Python"])
|
||||
res = self.successful_return_values(res)
|
||||
assert len(res) == 1
|
||||
assert res[0].who == BaseEvaluator.PREFIX + "Concept"
|
||||
assert res[0].body.body == "hello world"
|
||||
|
||||
def test_i_can_get_lexer_nodes_after_parsing_validation(self):
|
||||
sheerka, context, the, foo = self.init_concepts(
|
||||
Concept("the x", ret="x", where="isinstance(x, Concept)").def_var("x"),
|
||||
"foo",
|
||||
create_new=True)
|
||||
|
||||
parsed_ret_val = SyaNodeParser().parse(context, ParserInput("the foo"))
|
||||
validated_ret_val = ValidateConceptEvaluator().eval(context, parsed_ret_val)
|
||||
|
||||
res = core.builtin_helpers.get_lexer_nodes([validated_ret_val], 0, list(Tokenizer("the foo", yield_eof=False)))
|
||||
|
||||
assert isinstance(res, list)
|
||||
assert isinstance(res[0][0], ConceptNode)
|
||||
|
||||
def test_ensure_evaluated_returns_the_ret_value(self):
|
||||
"""
|
||||
When a concept has a RET defined, make sure to return it
|
||||
:return:
|
||||
"""
|
||||
|
||||
sheerka, context, foo, bar = self.init_concepts(
|
||||
"foo",
|
||||
Concept("bar", ret="foo")
|
||||
)
|
||||
|
||||
assert core.builtin_helpers.ensure_evaluated(context, bar) == foo
|
||||
|
||||
# a second time, now that bar is already evaluated
|
||||
assert core.builtin_helpers.ensure_evaluated(context, bar) == foo
|
||||
|
||||
# @pytest.mark.parametrize("return_values", [
|
||||
# None,
|
||||
# []
|
||||
|
||||
Reference in New Issue
Block a user