Added first version of DebugManager. Implemented draft of the rule engine
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
from core.builtin_concepts import ParserResultConcept, BuiltinConcepts
|
||||
from core.concept import Concept, CC
|
||||
from core.tokenizer import Tokenizer, TokenKind
|
||||
from parsers.SequenceNodeParser import SequenceNodeParser
|
||||
from parsers.BaseNodeParser import ConceptNode, UnrecognizedTokensNode, scnode, cnode, \
|
||||
utnode, SyaAssociativity, CN, CNC, UTN, SourceCodeWithConceptNode, SCWC, SourceCodeNode
|
||||
from parsers.BnfNodeParser import BnfNodeParser
|
||||
from parsers.SyaNodeParser import SyaNodeParser
|
||||
from parsers.UnrecognizedNodeParser import UnrecognizedNodeParser
|
||||
|
||||
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
||||
@@ -14,7 +17,7 @@ def get_input_nodes_from(my_concepts_map, full_expr, *args):
|
||||
if isinstance(n, CC):
|
||||
concept = n.concept or Concept.update_from(my_concepts_map[n.concept_key])
|
||||
for k, v in n.compiled.items():
|
||||
concept.compiled[k] = _get_real_node(v)
|
||||
concept.get_compiled()[k] = _get_real_node(v)
|
||||
return concept
|
||||
|
||||
if isinstance(n, (utnode, UTN)):
|
||||
@@ -26,7 +29,7 @@ def get_input_nodes_from(my_concepts_map, full_expr, *args):
|
||||
tokens = full_expr_as_tokens[n.start: n.end + 1]
|
||||
if hasattr(n, "compiled"):
|
||||
for k, v in n.compiled.items():
|
||||
concept.compiled[k] = _get_real_node(v)
|
||||
concept.get_compiled()[k] = _get_real_node(v)
|
||||
return ConceptNode(concept, n.start, n.end, tokens)
|
||||
|
||||
if isinstance(n, SCWC):
|
||||
@@ -118,45 +121,45 @@ class TestUnrecognizedNodeParser(TestUsingMemoryBasedSheerka):
|
||||
concept = res.body.concept
|
||||
assert concept == concepts_map["5params"]
|
||||
|
||||
assert len(concept.compiled["a"]) == 1
|
||||
assert sheerka.isinstance(concept.compiled["a"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
assert concept.compiled["a"][0].status
|
||||
assert concept.compiled["a"][0].who == "parsers.AtomNode"
|
||||
assert concept.compiled["a"][0].body.body == [cnode("one", 1, 1, "one")]
|
||||
assert len(concept.get_compiled()["a"]) == 1
|
||||
assert sheerka.isinstance(concept.get_compiled()["a"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
assert concept.get_compiled()["a"][0].status
|
||||
assert concept.get_compiled()["a"][0].who == "parsers." + SequenceNodeParser.NAME
|
||||
assert concept.get_compiled()["a"][0].body.body == [cnode("one", 1, 1, "one")]
|
||||
|
||||
assert len(concept.compiled["b"]) == 1
|
||||
assert sheerka.isinstance(concept.compiled["b"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
assert concept.compiled["b"][0].status
|
||||
assert concept.compiled["b"][0].who == "parsers.AtomNode"
|
||||
assert concept.compiled["b"][0].body.body == [cnode("two", 1, 1, "two"), cnode("three", 3, 3, "three")]
|
||||
assert len(concept.get_compiled()["b"]) == 1
|
||||
assert sheerka.isinstance(concept.get_compiled()["b"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
assert concept.get_compiled()["b"][0].status
|
||||
assert concept.get_compiled()["b"][0].who == "parsers." + SequenceNodeParser.NAME
|
||||
assert concept.get_compiled()["b"][0].body.body == [cnode("two", 1, 1, "two"), cnode("three", 3, 3, "three")]
|
||||
|
||||
assert len(concept.compiled["c"]) == 1
|
||||
assert sheerka.isinstance(concept.compiled["c"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
assert concept.compiled["c"][0].status
|
||||
assert concept.compiled["c"][0].who == "parsers.BnfNode"
|
||||
assert len(concept.get_compiled()["c"]) == 1
|
||||
assert sheerka.isinstance(concept.get_compiled()["c"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
assert concept.get_compiled()["c"][0].status
|
||||
assert concept.get_compiled()["c"][0].who == "parsers." + BnfNodeParser.NAME
|
||||
expected_nodes = compute_expected_array(
|
||||
concepts_map,
|
||||
" twenty one ",
|
||||
[CNC("twenties", source="twenty one", unit="one")])
|
||||
assert concept.compiled["c"][0].body.body == expected_nodes
|
||||
assert concept.get_compiled()["c"][0].body.body == expected_nodes
|
||||
|
||||
assert len(concept.compiled["d"]) == 1
|
||||
assert sheerka.isinstance(concept.compiled["d"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
assert concept.compiled["d"][0].status
|
||||
assert concept.compiled["d"][0].who == "parsers.Python"
|
||||
assert concept.compiled["d"][0].body.source == " 1 + 2 "
|
||||
assert len(concept.get_compiled()["d"]) == 1
|
||||
assert sheerka.isinstance(concept.get_compiled()["d"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
assert concept.get_compiled()["d"][0].status
|
||||
assert concept.get_compiled()["d"][0].who == "parsers.Python"
|
||||
assert concept.get_compiled()["d"][0].body.source == " 1 + 2 "
|
||||
|
||||
assert len(concept.compiled["e"]) == 1
|
||||
assert sheerka.isinstance(concept.compiled["e"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
assert concept.compiled["e"][0].status
|
||||
assert concept.compiled["e"][0].who == "parsers.SyaNode"
|
||||
assert len(concept.get_compiled()["e"]) == 1
|
||||
assert sheerka.isinstance(concept.get_compiled()["e"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
assert concept.get_compiled()["e"][0].status
|
||||
assert concept.get_compiled()["e"][0].who == "parsers." + SyaNodeParser.NAME
|
||||
expected_nodes = compute_expected_array(
|
||||
concepts_map,
|
||||
" one plus two mult three ",
|
||||
[CNC("plus", a="one", b=CC("mult", a="two", b="three"))],
|
||||
exclude_body=True)
|
||||
|
||||
assert concept.compiled["e"][0].body.body == expected_nodes
|
||||
assert concept.get_compiled()["e"][0].body.body == expected_nodes
|
||||
|
||||
# # sanity check, I can evaluate the concept
|
||||
# evaluated = sheerka.evaluate_concept(self.get_context(sheerka, eval_body=True), concept)
|
||||
@@ -177,25 +180,25 @@ class TestUnrecognizedNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
assert res.status
|
||||
assert res.body.concept == concepts_map["plus"]
|
||||
assert len(res.body.concept.compiled["a"]) == 1
|
||||
assert res.body.concept.compiled["a"][0].status
|
||||
assert res.body.concept.compiled["a"][0].who == "parsers.Python"
|
||||
assert res.body.concept.compiled["a"][0].body.source == "1 "
|
||||
assert len(res.body.concept.get_compiled()["a"]) == 1
|
||||
assert res.body.concept.get_compiled()["a"][0].status
|
||||
assert res.body.concept.get_compiled()["a"][0].who == "parsers.Python"
|
||||
assert res.body.concept.get_compiled()["a"][0].body.source == "1 "
|
||||
|
||||
assert res.body.concept.compiled["b"] == concepts_map["mult"]
|
||||
assert sheerka.isinstance(res.body.concept.compiled["b"].compiled["a"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
assert res.body.concept.compiled["b"].compiled["a"][0].status
|
||||
assert res.body.concept.compiled["b"].compiled["a"][0].who == "parsers.Python"
|
||||
assert res.body.concept.compiled["b"].compiled["a"][0].body.source == " 2 "
|
||||
assert res.body.concept.get_compiled()["b"] == concepts_map["mult"]
|
||||
assert sheerka.isinstance(res.body.concept.get_compiled()["b"].get_compiled()["a"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
assert res.body.concept.get_compiled()["b"].get_compiled()["a"][0].status
|
||||
assert res.body.concept.get_compiled()["b"].get_compiled()["a"][0].who == "parsers.Python"
|
||||
assert res.body.concept.get_compiled()["b"].get_compiled()["a"][0].body.source == " 2 "
|
||||
|
||||
assert sheerka.isinstance(res.body.concept.compiled["b"].compiled["b"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
assert res.body.concept.compiled["b"].compiled["b"][0].status
|
||||
assert res.body.concept.compiled["b"].compiled["b"][0].who == "parsers.BnfNode"
|
||||
assert sheerka.isinstance(res.body.concept.get_compiled()["b"].get_compiled()["b"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
assert res.body.concept.get_compiled()["b"].get_compiled()["b"][0].status
|
||||
assert res.body.concept.get_compiled()["b"].get_compiled()["b"][0].who == "parsers.Bnf"
|
||||
expected_nodes = compute_expected_array(
|
||||
concepts_map,
|
||||
" twenty two",
|
||||
[CNC("twenties", source="twenty two", unit="two")])
|
||||
assert res.body.concept.compiled["b"].compiled["b"][0].body.body == expected_nodes
|
||||
assert res.body.concept.get_compiled()["b"].get_compiled()["b"][0].body.body == expected_nodes
|
||||
|
||||
# def test_i_can_validate_and_evaluate_a_concept_node_with_python(self):
|
||||
# sheerka, context, parser = self.init_parser()
|
||||
@@ -211,12 +214,12 @@ class TestUnrecognizedNodeParser(TestUsingMemoryBasedSheerka):
|
||||
#
|
||||
# assert res.status
|
||||
# assert res.body.concept == concepts_map["plus"]
|
||||
# assert res.body.concept.compiled["a"] == concepts_map["one"]
|
||||
# assert len(res.body.concept.compiled["b"]) == 1
|
||||
# assert sheerka.isinstance(res.body.concept.compiled["b"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
# assert res.body.concept.compiled["b"][0].status
|
||||
# assert res.body.concept.compiled["b"][0].who == "parsers.Python"
|
||||
# assert res.body.concept.compiled["b"][0].body.source == "1 + 1"
|
||||
# assert res.body.concept.get_compiled()["a"] == concepts_map["one"]
|
||||
# assert len(res.body.concept.get_compiled()["b"]) == 1
|
||||
# assert sheerka.isinstance(res.body.concept.get_compiled()["b"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
# assert res.body.concept.get_compiled()["b"][0].status
|
||||
# assert res.body.concept.get_compiled()["b"][0].who == "parsers.Python"
|
||||
# assert res.body.concept.get_compiled()["b"][0].body.source == "1 + 1"
|
||||
#
|
||||
# # # evaluate
|
||||
# # context = self.get_context(sheerka, eval_body=True)
|
||||
@@ -231,10 +234,10 @@ class TestUnrecognizedNodeParser(TestUsingMemoryBasedSheerka):
|
||||
#
|
||||
# assert res.status
|
||||
# assert res.body.concept == concepts_map["plus"]
|
||||
# assert res.body.concept.compiled["a"] == concepts_map["one"]
|
||||
# assert len(res.body.concept.compiled["b"]) == 1
|
||||
# assert res.body.concept.compiled["b"][0].status
|
||||
# assert res.body.concept.compiled["b"][0].who == "parsers.BnfNode"
|
||||
# assert res.body.concept.get_compiled()["a"] == concepts_map["one"]
|
||||
# assert len(res.body.concept.get_compiled()["b"]) == 1
|
||||
# assert res.body.concept.get_compiled()["b"][0].status
|
||||
# assert res.body.concept.get_compiled()["b"][0].who == "parsers.BnfNode"
|
||||
#
|
||||
# # evaluate
|
||||
# context = self.get_context(sheerka, eval_body=True)
|
||||
@@ -336,7 +339,7 @@ class TestUnrecognizedNodeParser(TestUsingMemoryBasedSheerka):
|
||||
assert sheerka.isinstance(parser_result, BuiltinConcepts.PARSER_RESULT)
|
||||
assert parser_result.source == expression
|
||||
assert len(actual_nodes) == 1
|
||||
assert actual_nodes[0].nodes[0].concept.metadata.is_evaluated # 'a plus b' is recognized as concept definition
|
||||
assert actual_nodes[0].nodes[0].concept.get_metadata().is_evaluated # 'a plus b' is recognized as concept definition
|
||||
|
||||
def test_i_can_parse_unrecognized_source_code_with_concept_node_when_var_in_short_term_memory(self):
|
||||
sheerka, context, parser = self.init_parser()
|
||||
@@ -355,7 +358,7 @@ class TestUnrecognizedNodeParser(TestUsingMemoryBasedSheerka):
|
||||
assert sheerka.isinstance(parser_result, BuiltinConcepts.PARSER_RESULT)
|
||||
assert parser_result.source == expression
|
||||
assert len(actual_nodes) == 1
|
||||
assert not actual_nodes[0].nodes[0].concept.metadata.is_evaluated # 'a plus b' need to be evaluated
|
||||
assert not actual_nodes[0].nodes[0].concept.get_metadata().is_evaluated # 'a plus b' need to be evaluated
|
||||
|
||||
def test_i_can_parse_unrecognized_sya_concept_that_references_source_code(self):
|
||||
sheerka, context, parser = self.init_parser()
|
||||
@@ -381,8 +384,8 @@ class TestUnrecognizedNodeParser(TestUsingMemoryBasedSheerka):
|
||||
expression, [CN("hello_sya", source="hello get_user_name(twenty one)")],
|
||||
exclude_body=True)
|
||||
assert actual_nodes == expected_array
|
||||
assert isinstance(actual_nodes[0].concept.compiled["a"], list)
|
||||
assert sheerka.isinstance(actual_nodes[0].concept.compiled["a"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
assert isinstance(actual_nodes[0].concept.get_compiled()["a"], list)
|
||||
assert sheerka.isinstance(actual_nodes[0].concept.get_compiled()["a"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
|
||||
def test_i_can_parse_sequences(self):
|
||||
sheerka, context, parser = self.init_parser()
|
||||
|
||||
Reference in New Issue
Block a user