Fixed #125: SheerkaErrorManager
Fixed #135: Change services service priorities Fixed #136: ErrorManager: Implement recognize_error Fixed #137: BNFNodeParser : Error when parsing regex with sub parsers Fixed #138: get_last_errors(): real errors sources are lost Fixed #139: OneError return value removes the origin of the error Fixed #140: Concept variables are not correctly handled when parsing sub expression Fixed #143: Implement has_unknown_concepts()
This commit is contained in:
@@ -9,6 +9,7 @@ from core.global_symbols import NotInit
|
||||
from core.sheerka.services.SheerkaConceptManager import SheerkaConceptManager
|
||||
from core.sheerka.services.SheerkaExecute import ParserInput
|
||||
from core.sheerka.services.SheerkaIsAManager import SheerkaIsAManager
|
||||
from core.tokenizer import Tokenizer
|
||||
from parsers.BaseNodeParser import NoMatchingTokenError
|
||||
from parsers.BnfDefinitionParser import BnfDefinitionParser
|
||||
from parsers.BnfNodeParser import BnfNodeFirstTokenVisitor, BnfNodeParser, ConceptExpression, Match, NonTerminalNode, \
|
||||
@@ -1075,6 +1076,44 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
expected = [CNC("foo", "one onyx", x=CC("one"))]
|
||||
self.validate_get_concepts_sequences(my_map, text, expected)
|
||||
|
||||
def test_i_can_match_regex_when_sub_parser_input(self):
|
||||
my_map = {
|
||||
"foo": self.bnf_concept("foo", RegExMatch("[a-f0-9]{4}")),
|
||||
}
|
||||
text = "begin 0af0 end"
|
||||
parser_input = ParserInput(text).reset()
|
||||
sub_parser = parser_input.sub_part(2, 3)
|
||||
|
||||
sheerka, context, parser = self.init_parser(my_map)
|
||||
|
||||
res = parser.parse(context, sub_parser)
|
||||
|
||||
assert res.status
|
||||
concept_nodes = res.body.body
|
||||
|
||||
expected = [CN("foo", "0af0")]
|
||||
actual, expected = tests.parsers.parsers_utils.prepare_nodes_comparison(my_map, text, concept_nodes, expected)
|
||||
assert actual == expected
|
||||
|
||||
def test_i_can_match_regex_when_from_tokens(self):
|
||||
my_map = {
|
||||
"foo": self.bnf_concept("foo", RegExMatch("[a-f0-9]{4}")),
|
||||
}
|
||||
text = "begin 0af0 end"
|
||||
tokens = list(Tokenizer(text))
|
||||
parser_input = ParserInput(None, tokens[2:4]).reset()
|
||||
|
||||
sheerka, context, parser = self.init_parser(my_map)
|
||||
|
||||
res = parser.parse(context, parser_input)
|
||||
|
||||
assert res.status
|
||||
concept_nodes = res.body.body
|
||||
|
||||
expected = [CN("foo", "0af0")]
|
||||
actual, expected = tests.parsers.parsers_utils.prepare_nodes_comparison(my_map, "0af0", concept_nodes, expected)
|
||||
assert actual == expected
|
||||
|
||||
def test_i_can_reuse_the_same_variable(self):
|
||||
# in this test, the variable appears several times, but only once in concept.compiled
|
||||
my_map = {
|
||||
@@ -1831,7 +1870,7 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
assert not res.status
|
||||
assert sheerka.isinstance(res.body, BuiltinConcepts.NOT_FOR_ME)
|
||||
assert res.body.reason == [NoMatchingTokenError(4)]
|
||||
assert res.body.reason == [NoMatchingTokenError(4, concept=foo)]
|
||||
|
||||
@pytest.mark.parametrize("text", [
|
||||
"one",
|
||||
@@ -1852,7 +1891,7 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
(Sequence(StrMatch("foo"), VariableExpression("x")), "foo one"),
|
||||
(Sequence(StrMatch("foo"), VariableExpression("x"), StrMatch("bar")), "foo one bar"),
|
||||
])
|
||||
def test_i_cannot_parse_variable_when_unrecognized_nodes(self, bnf, text):
|
||||
def test_i_cannot_parse_variable_when_unrecognized_nodes(self, bnf, text):
|
||||
sheerka, context, foo = self.init_test().with_concepts(
|
||||
self.bnf_concept("foo", Sequence(VariableExpression("x"), StrMatch("shoe")))
|
||||
).unpack()
|
||||
|
||||
Reference in New Issue
Block a user