Added ZeroAndMore and OneAndMore to BNF. BNF expressions can now be captured
This commit is contained in:
@@ -5,9 +5,10 @@ class BaseEvaluator:
|
||||
|
||||
PREFIX = "Evaluators:"
|
||||
|
||||
def __init__(self, name, priority: int):
|
||||
def __init__(self, name, priority: int, enabled=True):
|
||||
self.name = self.PREFIX + name
|
||||
self.priority = priority
|
||||
self.enabled = enabled
|
||||
|
||||
|
||||
class OneReturnValueEvaluator(BaseEvaluator):
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user