aboutsummaryrefslogtreecommitdiff
path: root/py/makeqstrdata.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-04-14 23:38:37 +0100
committerDamien George <damien.p.george@gmail.com>2014-04-14 23:38:37 +0100
commit3683789207c4f7fc4b2909eaad4139de0806bac0 (patch)
treeca27b0ea7dbe5055f863ee2e17a7c4d92468cb95 /py/makeqstrdata.py
parentbc9ec5002d21efd6f2d28a1acad28e9085378e24 (diff)
py: Clean up and add comments to makeqstrdata.
Diffstat (limited to 'py/makeqstrdata.py')
-rw-r--r--py/makeqstrdata.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py
index e0917b336..eaff11bd0 100644
--- a/py/makeqstrdata.py
+++ b/py/makeqstrdata.py
@@ -25,13 +25,20 @@ def compute_hash(qstr):
return hash & 0xffff
# given a list of (name,regex) pairs, find the first one that matches the given line
-def re_match(regexs, line):
+def re_match_first(regexs, line):
for name, regex in regexs:
match = re.match(regex, line)
if match:
return name, match
return None, None
+# regexs to recognise lines that the CPP emits
+# use a list so that matching order is honoured
+cpp_regexs = [
+ ('qstr', r'Q\((.+)\)$'),
+ ('cdecl', r'(typedef|extern) [A-Za-z0-9_* ]+;$')
+]
+
def do_work(infiles):
# read the qstrs in from the input files
qstrs = {}
@@ -47,7 +54,7 @@ def do_work(infiles):
continue
# work out what kind of line it is
- match_kind, match = re_match([('qstr', r'Q\((.+)\)$'), ('cdecl', r'(typedef|extern) [A-Za-z0-9_* ]+;$')], line)
+ match_kind, match = re_match_first(cpp_regexs, line)
if match_kind is None:
# unknown line format
print('({}:{}) bad qstr format, got {}'.format(infile, line_number, line), file=sys.stderr)