@@ -212,12 +212,6 @@ class SpecParser(object):
212
212
('left' , 'LIST' , 'DICT' , 'SET' ),
213
213
)
214
214
215
- # regexp to extract pythran specs from comments
216
- # the first part matches lines with a comment and the pythran keyword
217
- # the second part matches lines with comments following the pythran ones
218
- FILTER = re .compile (r'^\s*#\s*pythran[^\n\r]*[\n\r]*'
219
- r'^(?:\s*#[^\n\r]*[\n\r]*)*' , re .MULTILINE )
220
-
221
215
def t_IDENTIFER (self , t ):
222
216
r'\#?[a-zA-Z_][a-zA-Z_0-9]*'
223
217
t .type = SpecParser .reserved .get (t .value , 'IDENTIFIER' )
@@ -414,11 +408,24 @@ def __call__(self, path_or_text):
414
408
self .input_file = None
415
409
416
410
data = self .read_path_or_text (path_or_text )
411
+ lines = []
412
+ in_pythran_export = False
413
+ for line in data .split ("\n " ):
414
+ if re .match (r'\s*#\s*pythran' , line ):
415
+ in_pythran_export = True
416
+ lines .append (re .sub (r'\s*#\s*pythran' , '#pythran' , line ))
417
+ elif in_pythran_export :
418
+ stripped = line .strip ()
419
+ if stripped .startswith ('#' ):
420
+ lines .append (line .replace ('#' , '' ))
421
+ else :
422
+ in_pythran_export = not stripped
423
+ lines .append ('' )
424
+ else :
425
+ in_pythran_export &= not line .strip ()
426
+ lines .append ('' )
417
427
418
- raw = "\n " .join (SpecParser .FILTER .findall (data ))
419
- pythran_data = (re .sub (r'#\s*pythran' , '\_o< pythran >o_/' , raw )
420
- .replace ('#' , '' )
421
- .replace ('\_o< pythran >o_/' , '#pythran' ))
428
+ pythran_data = '\n ' .join (lines )
422
429
self .parser .parse (pythran_data , lexer = self .lexer , debug = False )
423
430
424
431
for key , overloads in self .native_exports .items ():
0 commit comments