Commit d18be9ae authored by Stefan Behnel's avatar Stefan Behnel

support pure 'init' code in utility code files

parent f69ac182
...@@ -82,13 +82,13 @@ class UtilityCodeBase(object): ...@@ -82,13 +82,13 @@ class UtilityCodeBase(object):
# remember correct line numbers as least until after templating # remember correct line numbers as least until after templating
code = '\n' * begin_lineno + '\n'.join(lines) code = '\n' * begin_lineno + '\n'.join(lines)
if type == 'Proto': if type == 'proto':
utility[0] = code utility[0] = code
elif type == 'Code': elif type == 'impl':
utility[1] = code utility[1] = code
else: else:
all_tags = utility[2] all_tags = utility[2]
all_tags[type.lower()] = code all_tags[type] = code
if tags: if tags:
all_tags = utility[2] all_tags = utility[2]
...@@ -112,9 +112,10 @@ class UtilityCodeBase(object): ...@@ -112,9 +112,10 @@ class UtilityCodeBase(object):
comment = '/' comment = '/'
replace_comments = re.compile(r'^\s*//.*|^\s*/\*[^*]*\*/').sub replace_comments = re.compile(r'^\s*//.*|^\s*/\*[^*]*\*/').sub
match_special = re.compile( match_special = re.compile(
(r'^%(C)s{5,30}\s*((?:\w|\.)+)\s*%(C)s{5,30}|' (r'^%(C)s{5,30}\s*(?P<name>(?:\w|\.)+)\s*%(C)s{5,30}|'
r'^%(C)s+@(requires)\s*:\s*((?:\w|[.:])+)' # add more tag names here at need r'^%(C)s+@(?P<tag>requires)\s*:\s*(?P<value>(?:\w|[.:])+)' # add more tag names here at need
) % {'C':comment}).match ) % {'C':comment}).match
match_type = re.compile('(.+)[.](proto|impl|init|cleanup)$').match
f = Utils.open_source_file(filename, encoding='UTF-8') f = Utils.open_source_file(filename, encoding='UTF-8')
try: try:
...@@ -131,25 +132,22 @@ class UtilityCodeBase(object): ...@@ -131,25 +132,22 @@ class UtilityCodeBase(object):
for lineno, line in enumerate(all_lines): for lineno, line in enumerate(all_lines):
m = match_special(line) m = match_special(line)
if m: if m:
if m.group(1): if m.group('name'):
name = m.group(1)
cls._add_utility(utility, type, lines, begin_lineno, tags) cls._add_utility(utility, type, lines, begin_lineno, tags)
begin_lineno = lineno + 1 begin_lineno = lineno + 1
del lines[:] del lines[:]
tags.clear() tags.clear()
if name.endswith(".proto"): name = m.group('name')
name = name[:-6] mtype = match_type(name)
type = 'Proto' if mtype:
elif name.endswith(".cleanup"): name, type = mtype.groups()
name = name[:-8]
type = 'cleanup'
else: else:
type = 'Code' type = 'impl'
utility = utilities.setdefault(name, [None, None, {}]) utility = utilities.setdefault(name, [None, None, {}])
else: else:
tags.setdefault(m.group(2), set()).add(m.group(3)) tags.setdefault(m.group('tag'), set()).add(m.group('value'))
lines.append('') # keep line number correct lines.append('') # keep line number correct
else: else:
lines.append(replace_comments('', line).rstrip()) lines.append(replace_comments('', line).rstrip())
......
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