python3.2lua注释移除器。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python3.2lua注释移除器。相关的知识,希望对你有一定的参考价值。
Hi Guys,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. You can find some good comment examples on this site.
I would welcome your opinion.
# written in Python 3.2 import codecs import re inputFilePath = 'testfile.lua' inputLuaFile = codecs.open( inputFilePath, 'r', encoding = 'utf-8-sig' ) inputLuaFileDataList = inputLuaFile.read().split( " " ) 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 regexp comRegexpPatt = [( "oneLineS", r"--[^[]]*?$" ), ( "oneLine", r"--(?!(-|[|]))[^[]]*?$" ), ( "oneLineBlock", r"(?<!-)(--[[.*?]])" ), ( "blockS", r"(?<!-)--(?=([[)).*?$" ), ( "blockE", r".*?]]" ), ( "offBlockS", r"---+[[.*?$" ), ( "offBlockE", r".*?--]]" ), ] comRegexp = create_compile( comRegexpPatt ) comBlockState = False for 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( "{} ".format( i ) ) outputLuaFile.close()
以上是关于python3.2lua注释移除器。的主要内容,如果未能解决你的问题,请参考以下文章
flink 控制窗口行为(触发器移除器允许延迟将迟到的数据放入侧输出流)