diff --git a/tools/generation/lib/case.py b/tools/generation/lib/case.py index 5e9c97f66b..ed95c1c094 100644 --- a/tools/generation/lib/case.py +++ b/tools/generation/lib/case.py @@ -7,7 +7,7 @@ import re from .util.find_comments import find_comments from .util.parse_yaml import parse_yaml -regionStartPattern = re.compile(r'-\s+(\S+)(?P\s*.*)?') +regionStartPattern = re.compile(r'-\s+(\S+)(?P\s*.*)') metaPattern = r'\/\*---\n([\s]*)((?:\s|\S)*)[\n\s*]---\*\/' class Case: @@ -20,7 +20,7 @@ class Case: def _parse(self, source): case = dict(meta=None, regions=dict(), region_options=dict()) region_name = None - region_start = 0 + region_end = -1 region_options = None lines = source.split('\n') search = re.search(metaPattern, source, re.DOTALL|re.MULTILINE) @@ -31,22 +31,15 @@ class Case: if meta and not case['meta']: case['meta'] = meta - for comment in find_comments(source): + for comment in reversed(list(find_comments(source))): match = regionStartPattern.match(comment['source']) if match: - if region_name: - case['regions'][region_name] = \ - '\n'.join(lines[region_start:comment['lineno'] - 1]) - region_name = match.group(1) - region_start = comment['lineno'] + case['regions'][region_name] = \ + '\n'.join(lines[comment['lineno']:region_end]) region_options = match.group('options').split() if region_options: case['region_options'][region_name] = set(region_options) - continue - - if region_name: - case['regions'][region_name] = \ - '\n'.join(lines[region_start:-1]) + region_end = comment['lineno'] - 1 return case diff --git a/tools/generation/lib/template.py b/tools/generation/lib/template.py index 3bcfe85cff..cdc5276e89 100644 --- a/tools/generation/lib/template.py +++ b/tools/generation/lib/template.py @@ -93,11 +93,8 @@ class Template: continue match = interpolatePattern.match(comment['source']) - - if match == None: - continue - - self.regions.insert(0, dict(name=match.group(1), **comment)) + if match: + self.regions.insert(0, dict(name=match.group(1), **comment)) def expand_regions(self, source, context): lines = source.split('\n')