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


Python OneOrMore.transformString方法代码示例

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


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

示例1: main

# 需要导入模块: from pyparsing import OneOrMore [as 别名]
# 或者: from pyparsing.OneOrMore import transformString [as 别名]
def main(argv):
    """
    """
    group = OptionGroup("example", "OptionGroup Example", \
        "Shows all example options",
        option_list = [
            make_option("--example",
                        action="store_true",
                        dest="example",
                        help="An example option."),
        ]
    )

    parser = OptionParser("NAMES ...",
        description="A simple gobject.option example.",
        option_list = [
            make_option("--file", "-f",
                        type="filename",
                        action="store",
                        dest="file",
                        help="A filename option"),
            # ...
        ])

    parser.add_option_group(group)

    parser.parse_args()
    
    lineBody = SkipTo(lineEnd).setParseAction(mustBeNonBlank)

    # now define a line with a trailing lineEnd, to be replaced with a space character
    textLine = lineBody + Suppress(lineEnd).setParseAction(replaceWith(" "))

    # define a paragraph, with a separating lineEnd, to be replaced with a double newline
    para = OneOrMore(textLine) + Suppress(lineEnd).setParseAction(replaceWith("\n\n"))

    # run a test
    test = """
        Now is the
        time for
        all
        good men
        to come to

        the aid of their
        country.
    """
    print para.transformString(test)

    subdir_dir = Word(alphas, alphanums+"_")
    #macroDef = Suppress("SUBDIRS") + Suppress("=") + restOfLine
    subdir_dir_list = Suppress("SUBDIRS") + Suppress("=") + delimitedList( subdir_dir, " ", combine=True )
    macros = list(subdir_dir_list.searchString(subdirs_1line))
    print("1: subdirs of subdirs_1line are {}".format(macros))

    subdir_dir_list = Suppress("SUBDIRS") + Suppress("=") + delimitedList( subdir_dir, " ", combine=True )
    macros = list(subdir_dir_list.searchString(subdirs_2line))
    print("2: subdirs of subdirs_2line are {}".format(macros))

    subdir_dir_list = Suppress("SUBDIRS") + Suppress("=") + delimitedList( subdir_dir, " ", combine=False)
    macros = list(subdir_dir_list.searchString(subdirs_2line))
    print("2: subdirs of subdirs_2line are {}".format(macros))

    subdir_dir_list = Suppress("SUBDIRS") + Suppress("=") + \
        delimitedList( subdir_dir, " ", combine=False) + \
        Suppress(lineEnd)
    macros = list(subdir_dir_list.searchString(subdirs_3line))
    print("3: subdirs of subdirs_3line are {}".format(macros))

    # This returns a list!
    subdir_dir_list = Suppress("SUBDIRS") + Suppress("=") + \
        delimitedList( subdir_dir, " ", combine=False) + \
        SkipTo(lineEnd)
    macros = list(subdir_dir_list.searchString(subdirs_3line))
    print("3: subdirs of subdirs_3line are {}".format(macros))

    # This returns nothing because SUBDIRS is commented out!
    subdir_dir_list = Suppress(lineStart) + Suppress("SUBDIRS") + \
        Suppress("=") + delimitedList( subdir_dir, " ", combine=False) + \
        SkipTo(lineEnd)
    macros = list(subdir_dir_list.searchString(subdirs_4line))
    print("4: subdirs of subdirs_4line are {}".format(macros))

    # This returns 
    subdir_dir_list = Suppress(lineStart) + Suppress("SUBDIRS") + \
        Suppress("=") + delimitedList( subdir_dir, OneOrMore(" "), combine=False) + \
        SkipTo(lineEnd)
    macros = list(subdir_dir_list.searchString(subdirs_5line))
    print("5: subdirs of subdirs_5line are {}".format(macros))
    print("5a: subdirs of subdirs_5line are {}".\
        format(subdir_dir_list.scanString(subdirs_5line)))

    print "group: example ", group.values.example
    print "parser: file", parser.values.file

    res = 1
    try:
        pyparsing()
        print('{}'.format("pyparsing() done."))
        lun_q = r'''Lun:\s*(\d+(?:\s+\d+)*)'''
#.........这里部分代码省略.........
开发者ID:agander,项目名称:gander,代码行数:103,代码来源:rerun_autoconf.py


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