Skip to content

Commit f30d4d9

Browse files
More accurate parsing of #define directives
Support continuation lines and remove comments.
1 parent 5c196fb commit f30d4d9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

scripts/generate_psa_constants.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def __init__(self):
210210
# and the expansion in group 3.
211211
_define_directive_re = re.compile(r'\s*#\s*define\s+(\w+)' +
212212
r'(?:\s+|\((\w+)\)\s*)' +
213-
r'(.+)(?:/[*/])?')
213+
r'(.+)')
214214

215215
def read_line(self, line):
216216
"""Parse a C header line and record the PSA identifier it defines if any.
@@ -222,6 +222,7 @@ def read_line(self, line):
222222
if not m:
223223
return
224224
name, parameter, expansion = m.groups()
225+
expansion = re.sub(r'/\*.*?\*/|//.*', r' ', expansion)
225226
if name.endswith('_FLAG') or name.endswith('MASK'):
226227
# Macro only to build actual values
227228
return
@@ -274,6 +275,9 @@ def read_line(self, line):
274275

275276
def read_file(self, header_file):
276277
for line in header_file:
278+
while line.endswith('\\\n'):
279+
cont = next(header_file)
280+
line = line[:-2] + cont
277281
self.read_line(line)
278282

279283
@staticmethod

0 commit comments

Comments
 (0)