当前位置: 首页>>代码示例>>Python>>正文


Python Word.transformString方法代码示例

本文整理汇总了Python中pyparsing.Word.transformString方法的典型用法代码示例。如果您正苦于以下问题:Python Word.transformString方法的具体用法?Python Word.transformString怎么用?Python Word.transformString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyparsing.Word的用法示例。


在下文中一共展示了Word.transformString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from pyparsing import Word [as 别名]
# 或者: from pyparsing.Word import transformString [as 别名]
def main(argv):
    global verbose, keywords
    language = None

    opts, args = getopt(argv, 's:l:hvV', ['source=', 'language=', 'help', 'verbose', 'version'])
    for opt, arg in opts:
        if opt in ['-s', '--source']:
            source = arg
        elif opt in ['-l', '--language']:
            language = arg
        elif opt in ['-h', '--help']:
            # show usage
            usage()
            exit()
        elif opt in ['-v', '--verbose']:
            verbose = True
        elif opt in ['-V', '--version']:
            version()
            exit()

    try:
        if source:
            pass
    except:
        print('The source is not defined')
        usage()
        if verbose:
            print('exit')
        exit()

    try:
        if language:
            lang = importlib.import_module(language)
        else:
            lang = importlib.import_module('es')
    except:
        print('Error loading the language plugin')
        if verbose:
            print('exit')
        exit()

    keywords = lang.Keywords()

    # translation settings
    w = Word(alphas)
    w.ignore(quotedString)
    w.setParseAction(translate)

    # get all pi files inside root directory
    for root, dirs, files in os.walk(os.getcwd()):
        piFiles = fnmatch.filter(files, lang.FILE_PATTERN)

        if piFiles:
            for piFile in piFiles:
                # read pi file
                piCode = open(root + '/' + piFile, 'r').read()

                # translate pi file
                pyCode = w.transformString(piCode)

                # create python file
                fpy = open(root + '/' + splitext(piFile)[0] + '.py', 'w')
                fpy.write(pyCode)
                fpy.close()

    # read python file
    pythonCode = open(splitext(source)[0] + '.py', 'r').read()

    # exec python code
    exec pythonCode in {'__name__': '__main__', '__doc__': None}, {}
开发者ID:isjing,项目名称:piton,代码行数:72,代码来源:piton.py

示例2: OneOrMore

# 需要导入模块: from pyparsing import Word [as 别名]
# 或者: from pyparsing.Word import transformString [as 别名]
scopedIdent = ident + OneOrMore( Literal("::").suppress() + ident )
scopedIdent.setParseAction(lambda t: "_".join(t))

print("(replace namespace-scoped names with C-compatible names)")
print(scopedIdent.transformString( testData ))
    
    
# or a crude pre-processor (use parse actions to replace matching text)
def substituteMacro(s,l,t):
    if t[0] in macros:
        return macros[t[0]]
ident.setParseAction( substituteMacro )
ident.ignore(macroDef)

print("(simulate #define pre-processor)")
print(ident.transformString( testData ))



#################
print("Example of a stripper")
print("----------------------")

from pyparsing import dblQuotedString, LineStart

# remove all string macro definitions (after extracting to a string resource table?)
stringMacroDef = Literal("#define") + ident + "=" + dblQuotedString + LineStart()
stringMacroDef.setParseAction( replaceWith("") )

print(stringMacroDef.transformString( testData ))
开发者ID:0x0mar,项目名称:phpsploit,代码行数:32,代码来源:scanExamples.py

示例3: OneOrMore

# 需要导入模块: from pyparsing import Word [as 别名]
# 或者: from pyparsing.Word import transformString [as 别名]
scopedIdent = ident + OneOrMore( Literal("::").suppress() + ident )
scopedIdent.setParseAction(lambda t: "_".join(t))

print "(replace namespace-scoped names with C-compatible names)"
print scopedIdent.transformString( testData )
    
    
# or a crude pre-processor (use parse actions to replace matching text)
def substituteMacro(s,l,t):
    if t[0] in macros:
        return macros[t[0]]
ident.setParseAction( substituteMacro )
ident.ignore(macroDef)

print "(simulate #define pre-processor)"
print ident.transformString( testData )



#################
print "Example of a stripper"
print "----------------------"

from pyparsing import dblQuotedString, LineStart

# remove all string macro definitions (after extracting to a string resource table?)
stringMacroDef = Literal("#define") + ident + "=" + dblQuotedString + LineStart()
stringMacroDef.setParseAction( replaceWith("") )

print stringMacroDef.transformString( testData )
开发者ID:AmlaanKar96,项目名称:ArchC,代码行数:32,代码来源:scanExamples.py


注:本文中的pyparsing.Word.transformString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。