Skip to content

Commit c12242e

Browse files
committed
Merge pull request micropython#546 from stinos/relax-makeqstrdata
More relaxed parsing of preprocessed qstr header
2 parents 5874c1c + 1dc7f04 commit c12242e

File tree

1 file changed

+3
-31
lines changed

1 file changed

+3
-31
lines changed

py/makeqstrdata.py

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,43 +29,15 @@ def compute_hash(qstr):
2929
hash = (hash * 33) ^ ord(char)
3030
return hash & 0xffff
3131

32-
# given a list of (name,regex) pairs, find the first one that matches the given line
33-
def re_match_first(regexs, line):
34-
for name, regex in regexs:
35-
match = re.match(regex, line)
36-
if match:
37-
return name, match
38-
return None, None
39-
40-
# regexs to recognise lines that the CPP emits
41-
# use a list so that matching order is honoured
42-
cpp_regexs = [
43-
('qstr', r'Q\((.+)\)$'),
44-
('cdecl', r'(typedef|extern) [A-Za-z0-9_* ]+;$')
45-
]
46-
4732
def do_work(infiles):
4833
# read the qstrs in from the input files
4934
qstrs = {}
5035
for infile in infiles:
5136
with open(infile, 'rt') as f:
52-
line_number = 0
5337
for line in f:
54-
line_number += 1
55-
line = line.strip()
56-
57-
# ignore blank lines, comments and preprocessor directives
58-
if len(line) == 0 or line.startswith('//') or line.startswith('#'):
59-
continue
60-
61-
# work out what kind of line it is
62-
match_kind, match = re_match_first(cpp_regexs, line)
63-
if match_kind is None:
64-
# unknown line format
65-
print('({}:{}) bad qstr format, got {}'.format(infile, line_number, line), file=sys.stderr)
66-
return False
67-
elif match_kind != 'qstr':
68-
# not a line with a qstr
38+
# is this a QSTR line?
39+
match = re.match(r'^Q\((.+)\)$', line.strip())
40+
if not match:
6941
continue
7042

7143
# get the qstr value

0 commit comments

Comments
 (0)