mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 14:04:51 +02:00
Improve code clarity
This commit is contained in:
parent
20e06a147f
commit
52ff4171ab
@ -7,7 +7,7 @@ import re
|
|||||||
from .util.find_comments import find_comments
|
from .util.find_comments import find_comments
|
||||||
from .util.parse_yaml import parse_yaml
|
from .util.parse_yaml import parse_yaml
|
||||||
|
|
||||||
regionStartPattern = re.compile(r'-\s+(\S+)(?P<options>\s*.*)?')
|
regionStartPattern = re.compile(r'-\s+(\S+)(?P<options>\s*.*)')
|
||||||
metaPattern = r'\/\*---\n([\s]*)((?:\s|\S)*)[\n\s*]---\*\/'
|
metaPattern = r'\/\*---\n([\s]*)((?:\s|\S)*)[\n\s*]---\*\/'
|
||||||
|
|
||||||
class Case:
|
class Case:
|
||||||
@ -20,7 +20,7 @@ class Case:
|
|||||||
def _parse(self, source):
|
def _parse(self, source):
|
||||||
case = dict(meta=None, regions=dict(), region_options=dict())
|
case = dict(meta=None, regions=dict(), region_options=dict())
|
||||||
region_name = None
|
region_name = None
|
||||||
region_start = 0
|
region_end = -1
|
||||||
region_options = None
|
region_options = None
|
||||||
lines = source.split('\n')
|
lines = source.split('\n')
|
||||||
search = re.search(metaPattern, source, re.DOTALL|re.MULTILINE)
|
search = re.search(metaPattern, source, re.DOTALL|re.MULTILINE)
|
||||||
@ -31,22 +31,15 @@ class Case:
|
|||||||
if meta and not case['meta']:
|
if meta and not case['meta']:
|
||||||
case['meta'] = meta
|
case['meta'] = meta
|
||||||
|
|
||||||
for comment in find_comments(source):
|
for comment in reversed(list(find_comments(source))):
|
||||||
match = regionStartPattern.match(comment['source'])
|
match = regionStartPattern.match(comment['source'])
|
||||||
if match:
|
if match:
|
||||||
if region_name:
|
|
||||||
case['regions'][region_name] = \
|
|
||||||
'\n'.join(lines[region_start:comment['lineno'] - 1])
|
|
||||||
|
|
||||||
region_name = match.group(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()
|
region_options = match.group('options').split()
|
||||||
if region_options:
|
if region_options:
|
||||||
case['region_options'][region_name] = set(region_options)
|
case['region_options'][region_name] = set(region_options)
|
||||||
continue
|
region_end = comment['lineno'] - 1
|
||||||
|
|
||||||
if region_name:
|
|
||||||
case['regions'][region_name] = \
|
|
||||||
'\n'.join(lines[region_start:-1])
|
|
||||||
|
|
||||||
return case
|
return case
|
||||||
|
@ -93,11 +93,8 @@ class Template:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
match = interpolatePattern.match(comment['source'])
|
match = interpolatePattern.match(comment['source'])
|
||||||
|
if match:
|
||||||
if match == None:
|
self.regions.insert(0, dict(name=match.group(1), **comment))
|
||||||
continue
|
|
||||||
|
|
||||||
self.regions.insert(0, dict(name=match.group(1), **comment))
|
|
||||||
|
|
||||||
def expand_regions(self, source, context):
|
def expand_regions(self, source, context):
|
||||||
lines = source.split('\n')
|
lines = source.split('\n')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user