@@ -176,10 +176,13 @@ def filter(self, rec):
176
176
177
177
178
178
class ParsingException (Exception ):
179
- def __init__ (self , file : Optional [str ], lineno : int , line : str ):
179
+ def __init__ (self , file : Optional [str ], lineno : int , line : str , start : int = 0 ):
180
180
self .file = file
181
181
self .lineno = lineno
182
182
self .line = line
183
+ if start < 0 :
184
+ start = 0
185
+ self .start = start
183
186
184
187
def __str__ (self ):
185
188
out = ""
@@ -191,7 +194,9 @@ def __str__(self):
191
194
out += f"\n \n { lineno } { self .line } "
192
195
193
196
out += f'\n { " " * len (lineno )} '
194
- out += "^" * len (self .line .strip ())
197
+ if self .start :
198
+ out += " " * self .start
199
+ out += "^" * (len (self .line .strip ()) - self .start )
195
200
196
201
return out
197
202
@@ -204,6 +209,10 @@ class InvalidSyntax(ParsingException):
204
209
pass
205
210
206
211
212
+ class InvalidComment (ParsingException ):
213
+ pass
214
+
215
+
207
216
def extract_build_opt (name : str , dst : TextIO , src : TextIO ):
208
217
"""
209
218
Read src line by line and extract matching 'create-file' directives.
@@ -254,12 +263,18 @@ def extract_build_opt(name: str, dst: TextIO, src: TextIO):
254
263
state = IN_RAW
255
264
continue
256
265
257
- if line . startswith (( "#" , "//" , "*" )) :
266
+ if not line :
258
267
continue
259
268
260
- if not line :
269
+ # allow standalone comments on each line
270
+ if line .startswith (("#" , "//" , "*" )):
261
271
continue
262
272
273
+ # but not nested ones. this should get caught by -Wcomment, too
274
+ for comment in ("/*" , "*/" ):
275
+ if comment in line :
276
+ raise InvalidComment (None , n , raw_line , raw_line .index (comment ))
277
+
263
278
block .append (f"{ line } \n " )
264
279
265
280
if state != IN_RAW :
0 commit comments