Check in PatternParser that the generated Pattern is valid

This commit is contained in:
Raphaël Bournhonesque 2017-06-11 18:28:36 +02:00
parent e55199d454
commit 8ff4f512a2

View File

@ -38,8 +38,18 @@ class PatternParser(object):
if not pattern.nodes:
return
cls.check_pattern(pattern)
return pattern
@staticmethod
def check_pattern(pattern):
if not pattern.is_connected():
raise ValueError("The pattern tree must be a fully connected "
"graph.")
if pattern.root_node is None:
raise ValueError("The root node of the tree could not be found.")
@classmethod
def _parse_line(cls, stream, pattern, lineno):
while not stream.closed: