I had a job to remove all kinds of comments from the Lua file. I tried to find a usable Python script to this on the net, but Google did not help.  Therefore, I made one. This script recognizes all types of comments such as single and multi-Line comments.I would welcome your opinion.# written in Python 3.2import codecsimport reinputFilePath = 'testfile.lua'inputLuaFile = codecs.open( inputFilePath, 'r', encoding = 'utf-8-sig' )inputLuaFileDataList = inputLuaFile.read().split( \r\n )inputLuaFile.close()outputFilePath = 'testfile_out.lua'outputLuaFile = codecs.open( outputFilePath, 'w', encoding = 'utf-8' )outputLuaFile.write( codecs.BOM_UTF8.decode( utf-8 ) )def create_compile( patterns ):    compStr = '|'.join( '(?P<%s>%s)' % pair for pair in patterns )    regexp = re.compile( compStr )    return regexpcomRegexpPatt = [( oneLineS, r--[^\[\]]*?$ ),                 ( oneLine, r--(?!(-|\[|\]))[^\[\]]*?$ ),                 ( oneLineBlock, r(?<!-)(--\[\[.*?\]\]) ),                 ( blockS, r(?<!-)--(?=(\[\[)).*?$ ),                 ( blockE, r.*?\]\] ),                 ( offBlockS, r---+\[\[.*?$ ),                 ( offBlockE, r.*?--\]\] ),                 ]comRegexp = create_compile( comRegexpPatt )comBlockState = Falsefor i in inputLuaFileDataList:    res = comRegexp.search( i )    if res:        typ = res.lastgroup        if comBlockState:            if typ == blockE:                comBlockState = False                i = res.re.sub( , i )            else:                i =         else:            if typ == blockS:                comBlockState = True                i = res.re.sub( , i )            else:                comBlockState = False                i = res.re.sub( , i )    elif comBlockState:        i =     if not i == :        outputLuaFile.write( {}\n.format( i ) )
Lua comment remover
python