Added ZeroAndMore and OneAndMore to BNF. BNF expressions can now be captured

This commit is contained in:
2019-12-18 12:01:51 +01:00
parent 88cd3162be
commit 8dbe2e1b20
9 changed files with 425 additions and 91 deletions
+13 -5
View File
@@ -56,7 +56,7 @@ class ConceptNodeEvaluator(OneReturnValueEvaluator):
raise NotImplementedError("Not yet")
def update_concept(self, sheerka, concept, underlying):
def update_concept(self, sheerka, concept, underlying, init_empty_body=True):
"""
Updates the property of the concept
"""
@@ -69,14 +69,22 @@ class ConceptNodeEvaluator(OneReturnValueEvaluator):
if prop_name not in c.props or c.props[prop_name].value is None:
c.set_prop(prop_name, value)
else:
new_value = [c.props[prop_name].value, value]
c.set_prop(prop_name, new_value)
previous_value = c.props[prop_name].value
if isinstance(previous_value, list):
previous_value.append(value)
else:
new_value = [previous_value, value]
c.set_prop(prop_name, new_value)
parsing_expression = underlying.parsing_expression
if parsing_expression.rule_name:
_add_prop(concept, parsing_expression.rule_name, underlying.source)
# the update of the body must come BEFORE the recursion
if init_empty_body and concept.body is None:
concept.metadata.body = underlying.source
if isinstance(underlying, NonTerminalNode):
for child in underlying.children:
if isinstance(child.parsing_expression, ConceptMatch):
@@ -85,8 +93,8 @@ class ConceptNodeEvaluator(OneReturnValueEvaluator):
if sheerka.isinstance(new_concept, BuiltinConcepts.UNKNOWN_CONCEPT):
continue
else:
self.update_concept(sheerka, new_concept, child.children[0])
self.update_concept(sheerka, new_concept, child.children[0], init_empty_body)
else:
self.update_concept(sheerka, concept, child)
self.update_concept(sheerka, concept, child, init_empty_body)
return concept