#NEWLINE# def _strip_regex( pattern , text , preserve_lines ) : #NEWLINE# #INDENT# 'Generic function that strips out comments pased on the given pattern.' #NEWLINE# def remove_comments( group , preserve_lines = False ) : #NEWLINE# #INDENT# 'Remove comments.' #NEWLINE# return ( '' . join ( [ x [ 0 ] for x in LINE_PRESERVE . findall ( group ) ] ) if preserve_lines else '' ) #NEWLINE# #UNINDENT# def evaluate( m , preserve_lines ) : #NEWLINE# #INDENT# 'Search for comments.' #NEWLINE# g = m . groupdict ( ) #NEWLINE# return ( g [ 'code' ] if ( g [ 'code' ] is not None ) else remove_comments ( g [ 'comments' ] , preserve_lines ) ) #NEWLINE# #UNINDENT# return '' . join ( map ( ( lambda m : evaluate ( m , preserve_lines ) ) , pattern . finditer ( evaluate ) ) )