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


Python Word.ignore方法代码示例

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


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

示例1: main

# 需要导入模块: from pyparsing import Word [as 别名]
# 或者: from pyparsing.Word import ignore [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: print

# 需要导入模块: from pyparsing import Word [as 别名]
# 或者: from pyparsing.Word import ignore [as 别名]
print("----------------------")

# convert C++ namespaces to mangled C-compatible names
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("") )
开发者ID:0x0mar,项目名称:phpsploit,代码行数:33,代码来源:scanExamples.py

示例3: Scope

# 需要导入模块: from pyparsing import Word [as 别名]
# 或者: from pyparsing.Word import ignore [as 别名]
  return Scope(t[0][0])


if_ = Keyword("if")
elif_ = Keyword("elif")
else_ = Keyword("else")
return_ = Keyword("return")
define = Keyword("define")
while_ = Keyword("while")
true = Keyword("true")
false = Keyword("false")
any_keyword = if_ | elif_ | else_ | return_ | define | while_ | true | false

identifier = Word(alphas+'_',alphanums+"_")
identifier.setParseAction(identifier_fn)
identifier.ignore(any_keyword)

# Proto-specific parsing
def proto_integer_fn(s,l,t):
  return ProtoInteger(int(t[0]))
def proto_string_fn(s,l,t):
  return String(t[0])
def proto_data_fn(s,l,t):
  return ProtoData(t[0])
def top_level_proto_definition_fn(s,l,t):
  return TopLevelProtoDefinition(t[0], t[1])
def nested_proto_fn(s,l,t):
  return NestedProto(t[0], t[1])
def proto_parser_fn(s,l,t):
  return ProtoParser(t)
开发者ID:google,项目名称:protocall,代码行数:32,代码来源:grammar.py


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