Commit 3d95076e authored by eckhart's avatar eckhart
Browse files

- bugfix: namend empty nodes will not be dropped any more.

parent d9fbc53c
...@@ -1401,6 +1401,16 @@ class MetaParser(Parser): ...@@ -1401,6 +1401,16 @@ class MetaParser(Parser):
return EMPTY_NODE # avoid creation of a node object for anonymous empty nodes return EMPTY_NODE # avoid creation of a node object for anonymous empty nodes
return Node(self.tag_name, results) # unoptimized code return Node(self.tag_name, results) # unoptimized code
def _keep_node(self, node):
"""
Returns True, if a node returned by a descendant parser should be kept.
False, if it should be sorted out. A node is kept, if it is empty and
neither the parser of the descendant parser is a named parser.
"""
if self.grammar.flatten_tree__:
return node._result or node.tag_name[0:1] != ':'
return node != EMPTY_NODE # EMPTY_NODE will always be sorted out...
class UnaryParser(MetaParser): class UnaryParser(MetaParser):
""" """
...@@ -1538,7 +1548,7 @@ class ZeroOrMore(Option): ...@@ -1538,7 +1548,7 @@ class ZeroOrMore(Option):
node, text = self.parser(text) node, text = self.parser(text)
if not node: if not node:
break break
if node._result or self.parser.pname: if self._keep_node(node):
results += (node,) results += (node,)
if len(text) == n: if len(text) == n:
break # avoid infinite loop break # avoid infinite loop
...@@ -1589,7 +1599,7 @@ class OneOrMore(UnaryParser): ...@@ -1589,7 +1599,7 @@ class OneOrMore(UnaryParser):
if not node: if not node:
break break
match_flag = True match_flag = True
if node._result or self.parser.pname: if self._keep_node(node):
results += (node,) results += (node,)
if len(text_) == n: if len(text_) == n:
break # avoid infinite loop break # avoid infinite loop
...@@ -1748,7 +1758,7 @@ class Series(NaryParser): ...@@ -1748,7 +1758,7 @@ class Series(NaryParser):
else: else:
results += (node,) results += (node,)
break break
if node._result or parser.pname or node.tag_name[0:1] != ':': # optimization if self._keep_node(node): # optimization
results += (node,) results += (node,)
# assert len(results) <= len(self.parsers) \ # assert len(results) <= len(self.parsers) \
# or len(self.parsers) >= len([p for p in results if p.tag_name != ZOMBIE_TAG]) # or len(self.parsers) >= len([p for p in results if p.tag_name != ZOMBIE_TAG])
...@@ -1950,7 +1960,7 @@ class AllOf(NaryParser): ...@@ -1950,7 +1960,7 @@ class AllOf(NaryParser):
for i, parser in enumerate(parsers): for i, parser in enumerate(parsers):
node, text__ = parser(text_) node, text__ = parser(text_)
if node: if node:
if node._result or parser.pname: if self._keep_node(node):
results += (node,) results += (node,)
text_ = text__ text_ = text__
del parsers[i] del parsers[i]
...@@ -2017,7 +2027,7 @@ class SomeOf(NaryParser): ...@@ -2017,7 +2027,7 @@ class SomeOf(NaryParser):
for i, parser in enumerate(parsers): for i, parser in enumerate(parsers):
node, text__ = parser(text_) node, text__ = parser(text_)
if node: if node:
if node._result or parser.pname: if self._keep_node(node):
results += (node,) results += (node,)
text_ = text__ text_ = text__
del parsers[i] del parsers[i]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment