Skip to content

Commit 3683789

Browse files
committed
py: Clean up and add comments to makeqstrdata.
1 parent bc9ec50 commit 3683789

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

py/makeqstrdata.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,20 @@ def compute_hash(qstr):
2525
return hash & 0xffff
2626

2727
# given a list of (name,regex) pairs, find the first one that matches the given line
28-
def re_match(regexs, line):
28+
def re_match_first(regexs, line):
2929
for name, regex in regexs:
3030
match = re.match(regex, line)
3131
if match:
3232
return name, match
3333
return None, None
3434

35+
# regexs to recognise lines that the CPP emits
36+
# use a list so that matching order is honoured
37+
cpp_regexs = [
38+
('qstr', r'Q\((.+)\)$'),
39+
('cdecl', r'(typedef|extern) [A-Za-z0-9_* ]+;$')
40+
]
41+
3542
def do_work(infiles):
3643
# read the qstrs in from the input files
3744
qstrs = {}
@@ -47,7 +54,7 @@ def do_work(infiles):
4754
continue
4855

4956
# work out what kind of line it is
50-
match_kind, match = re_match([('qstr', r'Q\((.+)\)$'), ('cdecl', r'(typedef|extern) [A-Za-z0-9_* ]+;$')], line)
57+
match_kind, match = re_match_first(cpp_regexs, line)
5158
if match_kind is None:
5259
# unknown line format
5360
print('({}:{}) bad qstr format, got {}'.format(infile, line_number, line), file=sys.stderr)

0 commit comments

Comments
 (0)