def filtercomments(source):
 trailing_comments = []
 comment = True
 while comment:
  if re.search('^\\s*\\/\\*', source):
   comment = source[(0, (source.index('*/') + 2))]
  elif re.search('^\\s*\\/\\/', source):
   comment = re.search('^\\s*\\/\\/', source).group(0)
  else:
   comment = None
  if comment:
   source = re.sub('^\\s+', '', source[len(comment):])
   trailing_comments.append(comment)
 return ('\n'.join(trailing_comments) + source)

def filtercomments ( source ) : trailing_comments = [ ] comment = True while comment : if re . search ( '^\\s*\\/\\*' , source ) : comment = source [ ( 0 , ( source . index ( '*/' ) + 2 ) ) ] elif re . search ( '^\\s*\\/\\/' , source ) : comment = re . search ( '^\\s*\\/\\/' , source ) . group ( 0 ) else : comment = None if comment : source = re . sub ( '^\\s+' , '' , source [ len ( comment ) : ] ) trailing_comments . append ( comment ) return ( '\n' . join ( trailing_comments ) + source )
not used: strips trailing comments and put them at the top .