We can now use concept sets in BNF definitions

This commit is contained in:
2020-01-19 21:48:43 +01:00
parent a7b239c167
commit 821614a6c4
16 changed files with 643 additions and 93 deletions
+41 -3
View File
@@ -61,6 +61,7 @@ def get_expected(concept, text=None):
c = Concept(name=concept.name)
c.compiled[ConceptParts.BODY] = DoNotResolve(text or concept.name)
c.init_key()
c.metadata.id = concept.id
return c
@@ -606,9 +607,6 @@ def test_i_can_parse_concept_reference_that_is_not_in_grammar():
grammar = {foo: Sequence("twenty", OrderedChoice(one, two))}
context, parser = init([one, two, foo], grammar)
parser = ConceptLexerParser()
parser.initialize(context, grammar)
res = parser.parse(context, "twenty two")
assert res.status
assert res.value.body == [cnode("foo", 0, 2, "twenty two")]
@@ -621,6 +619,46 @@ def test_i_can_parse_concept_reference_that_is_not_in_grammar():
assert res.value.body == [cnode("foo", 0, 2, "twenty one")]
def test_i_can_parse_concept_reference_that_is_group():
"""
if one is number, then number is a 'group'
a group can be found under the sdp entry 'all_<group_name>'
"""
context = get_context()
one = Concept(name="one")
two = Concept(name="two")
number = Concept(name="number")
foo = Concept(name="foo")
for c in [one, two, number, foo]:
context.sheerka.set_id_if_needed(c, False)
context.sheerka.add_in_cache(c)
context.sheerka.add_concept_to_set(context, one, number)
context.sheerka.add_concept_to_set(context, two, number)
grammar = {foo: Sequence("twenty", number)}
parser = ConceptLexerParser()
parser.initialize(context, grammar)
res = parser.parse(context, "twenty two")
assert res.status
assert res.value.body == [cnode("foo", 0, 2, "twenty two")]
concept_found = res.value.body[0].concept
assert cbody(concept_found) == DoNotResolve("twenty two")
assert cprop(concept_found, "two") == get_expected(two, "two")
assert cprop(concept_found, "number") == get_expected(number, get_expected(two, "two"))
res = parser.parse(context, "twenty one")
assert res.status
assert res.value.body == [cnode("foo", 0, 2, "twenty one")]
concept_found = res.value.body[0].concept
assert cbody(concept_found) == DoNotResolve("twenty one")
assert cprop(concept_found, "one") == get_expected(one, "one")
assert cprop(concept_found, "number") == get_expected(number, get_expected(one, "one"))
def test_i_can_parse_zero_or_more():
foo = Concept(name="foo")
grammar = {foo: ZeroOrMore("one")}