Added first version of DebugManager. Implemented draft of the rule engine
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.concept import Concept, CIO
|
||||
from core.sheerka.services.SheerkaComparisonManager import SheerkaComparisonManager
|
||||
from core.concept import Concept, CIO, ALL_ATTRIBUTES
|
||||
from core.global_symbols import CONCEPT_COMPARISON_CONTEXT
|
||||
from core.sheerka.services.SheerkaExecute import ParserInput
|
||||
from core.tokenizer import Tokenizer
|
||||
from parsers.BaseNodeParser import utnode, ConceptNode, cnode, short_cnode, UnrecognizedTokensNode, \
|
||||
@@ -54,14 +54,16 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
|
||||
cmap["plus"].set_prop(BuiltinConcepts.ASSOCIATIVITY, "right")
|
||||
cmap["mult"].set_prop(BuiltinConcepts.ASSOCIATIVITY, "right")
|
||||
cmap["minus"].set_prop(BuiltinConcepts.ASSOCIATIVITY, "right")
|
||||
TestSyaNodeParser.sheerka.services[SheerkaComparisonManager.NAME].set_is_greater_than(context,
|
||||
BuiltinConcepts.PRECEDENCE,
|
||||
cmap["mult"],
|
||||
cmap["plus"])
|
||||
TestSyaNodeParser.sheerka.services[SheerkaComparisonManager.NAME].set_is_greater_than(context,
|
||||
BuiltinConcepts.PRECEDENCE,
|
||||
cmap["mult"],
|
||||
cmap["minus"])
|
||||
TestSyaNodeParser.sheerka.set_is_greater_than(context,
|
||||
BuiltinConcepts.PRECEDENCE,
|
||||
cmap["mult"],
|
||||
cmap["plus"],
|
||||
CONCEPT_COMPARISON_CONTEXT)
|
||||
TestSyaNodeParser.sheerka.set_is_greater_than(context,
|
||||
BuiltinConcepts.PRECEDENCE,
|
||||
cmap["mult"],
|
||||
cmap["minus"],
|
||||
CONCEPT_COMPARISON_CONTEXT)
|
||||
|
||||
# TestSyaNodeParser.sheerka.force_sya_def(context, [
|
||||
# (cmap["plus"].id, 5, SyaAssociativity.Right),
|
||||
@@ -91,6 +93,7 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
|
||||
sheerka = TestSyaNodeParser.sheerka
|
||||
context = self.get_context(sheerka)
|
||||
concepts = cmap.values()
|
||||
ALL_ATTRIBUTES.clear()
|
||||
|
||||
if post_init_concepts:
|
||||
post_init_concepts(sheerka, context)
|
||||
@@ -967,7 +970,7 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
|
||||
' 7:<ws> => PUSH_UNREC',
|
||||
' 8:: => ??',
|
||||
" _: => RECOG [[UTN('twenty '), CN((1001)one)], [CN((1016)twenties)]]",
|
||||
" _: => POP ConceptNode(concept='(1016)twenties', source='twenty one', start=4, end=6, ConceptParts.BODY='DoNotResolve(value='twenty one')', unit='(1001)one')",
|
||||
" _: => POP ConceptNode(concept='(1016)twenties', source='twenty one', start=4, end=6, #body#='DoNotResolve(value='twenty one')', unit='(1001)one')",
|
||||
' 9:<ws> => EAT',
|
||||
' 10:three => PUSH_UNREC',
|
||||
' 11:<EOF> => ??',
|
||||
@@ -978,7 +981,7 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
|
||||
])
|
||||
def test_i_can_debug(self, expression, expected_debugs):
|
||||
sheerka, context, parser = self.init_parser()
|
||||
context.add_to_private_hints(BuiltinConcepts.DEBUG)
|
||||
context.debug_enabled = True
|
||||
res = parser.infix_to_postfix(context, ParserInput(expression))
|
||||
|
||||
assert len(res) == len(expected_debugs)
|
||||
@@ -1000,10 +1003,10 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
# check the compiled
|
||||
expected_concept = lexer_nodes[0].concept
|
||||
assert expected_concept.compiled["a"] == cmap["one"]
|
||||
assert expected_concept.compiled["b"] == cmap["mult"]
|
||||
assert expected_concept.compiled["b"].compiled["a"] == cmap["two"]
|
||||
assert expected_concept.compiled["b"].compiled["b"] == cmap["three"]
|
||||
assert expected_concept.get_compiled()["a"] == cmap["one"]
|
||||
assert expected_concept.get_compiled()["b"] == cmap["mult"]
|
||||
assert expected_concept.get_compiled()["b"].get_compiled()["a"] == cmap["two"]
|
||||
assert expected_concept.get_compiled()["b"].get_compiled()["b"] == cmap["three"]
|
||||
|
||||
def test_i_can_parse_when_python_code(self):
|
||||
sheerka, context, parser = self.init_parser()
|
||||
@@ -1019,9 +1022,9 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
# check the compiled
|
||||
expected_concept = lexer_nodes[0].concept
|
||||
assert len(expected_concept.compiled["a"]) == 1
|
||||
assert len(expected_concept.get_compiled()["a"]) == 1
|
||||
|
||||
return_value_a = expected_concept.compiled["a"][0]
|
||||
return_value_a = expected_concept.get_compiled()["a"][0]
|
||||
assert sheerka.isinstance(return_value_a, BuiltinConcepts.RETURN_VALUE)
|
||||
assert return_value_a.status
|
||||
assert sheerka.isinstance(return_value_a.body, BuiltinConcepts.PARSER_RESULT)
|
||||
@@ -1044,8 +1047,8 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
# check the compiled
|
||||
expected_concept = lexer_nodes[0].concept
|
||||
assert sheerka.isinstance(expected_concept.compiled["a"], "twenties")
|
||||
assert expected_concept.compiled["a"].compiled["unit"] == cmap["one"]
|
||||
assert sheerka.isinstance(expected_concept.get_compiled()["a"], "twenties")
|
||||
assert expected_concept.get_compiled()["a"].get_compiled()["unit"] == cmap["one"]
|
||||
|
||||
def test_i_can_parse_sequences(self):
|
||||
sheerka, context, parser = self.init_parser()
|
||||
@@ -1062,9 +1065,9 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
|
||||
ConceptNode(cmap["suffixed"], 10, 12, source="suffixed two")]
|
||||
|
||||
# check the compiled
|
||||
concept_plus_a = lexer_nodes[0].concept.compiled["a"]
|
||||
concept_plus_b = lexer_nodes[0].concept.compiled["b"]
|
||||
concept_suffixed_a = lexer_nodes[1].concept.compiled["a"]
|
||||
concept_plus_a = lexer_nodes[0].concept.get_compiled()["a"]
|
||||
concept_plus_b = lexer_nodes[0].concept.get_compiled()["b"]
|
||||
concept_suffixed_a = lexer_nodes[1].concept.get_compiled()["a"]
|
||||
|
||||
assert concept_plus_a == cmap["one"]
|
||||
assert len(concept_plus_b) == 1
|
||||
@@ -1199,7 +1202,7 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
concept_found = lexer_nodes[0].concept
|
||||
for unrecognized in expected_unrecognized:
|
||||
assert isinstance(concept_found.compiled[unrecognized], UnrecognizedTokensNode)
|
||||
assert isinstance(concept_found.get_compiled()[unrecognized], UnrecognizedTokensNode)
|
||||
|
||||
@pytest.mark.parametrize("text, expected", [
|
||||
("x$!# suffixed one", [utnode(0, 4, "x$!# "), cnode("suffixed __var__0", 5, 7, "suffixed one")]),
|
||||
|
||||
Reference in New Issue
Block a user