本文整理汇总了Python中pyparsing.Suppress.transformString方法的典型用法代码示例。如果您正苦于以下问题:Python Suppress.transformString方法的具体用法?Python Suppress.transformString怎么用?Python Suppress.transformString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyparsing.Suppress
的用法示例。
在下文中一共展示了Suppress.transformString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyparsing import Suppress [as 别名]
# 或者: from pyparsing.Suppress import transformString [as 别名]
def main():
filename = sys.argv[1]
source = open(filename).read()
commentFilter = Suppress( javaStyleComment ).ignore( dblQuotedString )
source = commentFilter.transformString(source)
source = source.replace('\r\n', '\n')
source = source.replace('\r', '')
for m in re.finditer('#pragma[ \t][ \t]*pskel.*\n', source):
pragma = m.group(0)
begin = m.start(0)
end = m.end(0)+1
while pragma.strip()[-1]=='\\':
pragma = pragma.strip()[:-1].strip()
tmp = ''
while source[end]!='\n':
tmp += source[end]
end += 1
pragma += ' '+tmp.strip()
end += 1
pragma = pragma.strip()
print begin, end
print pragma
#print source[begin:end]
pinfo = parsePragma(pragma)
print pinfo
fcall = readFuncCall(source,end)
print fcall
kfunc = findFunctionDef(source,fcall[0])
print source[fcall[2]:fcall[3]]
mainf = readOutterFunction(source, begin)
#print mainf
fcall_name = '_pskelcc_stencil_'+str(fcall[2])+'_'+str(fcall[3])
tmainf = mainf['src'].replace(source[begin:end],'\n').replace(source[fcall[2]:fcall[3]],fcall_name+'();')
print tmainf
parser = c_parser.CParser()
ast = parser.parse(tmainf)
pgen = PSkelGenerator(pinfo,fcall_name)
new_mainf = pgen.visit(ast)
parser = c_parser.CParser()
ast = parser.parse(kfunc['src'])
pgen = PSkelKernelGenerator(pinfo)
new_kfunc = pgen.visit(ast)
f = open(sys.argv[2],'w')
f.write('#define PSKEL_OMP\n')
if pinfo['device']=='gpu':
f.write('#define PSKEL_CUDA\n')
f.write('''
#include "include/PSkel.h"
using namespace PSkel;\n\n''')
f.write(source[:kfunc['begin']]+new_kfunc+source[kfunc['end']:mainf['begin']]+new_mainf+source[mainf['end']:])
f.close()
示例2: parse_ttable
# 需要导入模块: from pyparsing import Suppress [as 别名]
# 或者: from pyparsing.Suppress import transformString [as 别名]
def parse_ttable(f):
ttable = {}
# com = Suppress('[') + ZeroOrMore(CharsNotIn(']')) + Suppress(']')
com = Suppress('[' + ZeroOrMore(CharsNotIn(']') + ']'))
while True:
s = next(f).strip()
if not s:
continue
s = com.transformString(s).strip()
if s.lower() == ";":
break
b = False
if s[-1] in ",;":
if s[-1] == ';':
b = True
s = s[:-1]
# print(s)
k, v = s.split()
ttable[k] = v
if b:
break
return ttable
示例3: main
# 需要导入模块: from pyparsing import Suppress [as 别名]
# 或者: from pyparsing.Suppress import transformString [as 别名]
def main():
filename = sys.argv[1]
source = open(filename).read()
commentFilter = Suppress( javaStyleComment ).ignore( dblQuotedString )
source = commentFilter.transformString(source)
source = source.replace('\r\n', '\n')
source = source.replace('\r', '')
for m in re.finditer('#pragma[ \t][ \t]*pskel.*\n', source):
pragma = m.group(0)
begin = m.start(0)
end = m.end(0)+1
while pragma.strip()[-1]=='\\':
pragma = pragma.strip()[:-1].strip()
tmp = ''
while source[end]!='\n':
tmp += source[end]
end += 1
pragma += ' '+tmp.strip()
end += 1
pragma = pragma.strip()
print begin, end
print pragma
print source[begin:end]
pinfo = parsePragma(pragma)
print pinfo
fcall = readFuncCall(source,end)
print fcall
extraArgs = parseExtraArgs(fcall['args'],pinfo)
print 'ExtraArgs:',extraArgs
if len(extraArgs)>0:
print 'TODO: create a struct for passing the extra arguments to the PSkel stencil kernel'
print 'gather the types of the extra arguments from the original kernel function declaration'
kfunc = findFunctionDef(source,fcall['name'])
print fcall['src']
mainf = readOutterFunction(source, begin)
#print mainf
fcall_name = '_pskelcc_stencil_'+str(fcall['begin'])+'_'+str(fcall['end'])
tmainf = mainf['src'].replace(source[begin:end],'\n').replace(fcall['src'],fcall_name+'();')
print tmainf
parser = c_parser.CParser()
ast = parser.parse(tmainf)
pgen = PSkelGenerator(pinfo,fcall_name)
new_mainf = pgen.visit(ast)
receivedParameters = pgen.receivedParameters
parser = c_parser.CParser()
ast = parser.parse(kfunc['src'])
pgen = PSkelKernelGenerator(pinfo)
new_kfunc = pgen.visit(ast)
src = source.replace(mainf['src'],new_mainf).replace(kfunc['src'],new_kfunc)
while len(receivedParameters)>0:
print 'TODO: Trace arguments back to original definition',pgen.receivedParameters
print 'Searching for caller of function',mainf['name']
#print findFunctionCall(src,mainf['name'])
receivedParameters = []
#src = src.replace(...)
f = open(sys.argv[2],'w')
f.write('#define PSKEL_OMP\n')
if pinfo['device']=='gpu':
f.write('#define PSKEL_CUDA\n')
f.write('''
#include "PSkel.h"
using namespace PSkel;\n\n''')
f.write(src)
f.close()