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


Python Group.ignore方法代码示例

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


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

示例1: parse_config_file

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import ignore [as 别名]
def parse_config_file(filepath):
    """
    This function defines that to parsed the netscalar input file
    :param filepath: path of netscalar input configuration
    :return: return parsed dict
    """

    EOL = LineEnd().suppress()
    comment = Suppress("#") + Suppress(restOfLine) + EOL
    SOL = LineStart().suppress()
    blank_line = SOL + EOL
    result = []
    hyphen = Literal("-")
    not_hyphen_sign = ''.join(c for c in printables if c != '-')
    text = Word(not_hyphen_sign, printables)
    key = Word('-', printables).setParseAction(
        lambda t: t[0].replace('-', '', 1))
    val = originalTextFor(Optional(ZeroOrMore(text), default=None))
    option = Group(key + val)
    multi_word_names = quotedString
    q_obj = originalTextFor(Keyword('q{')+SkipTo(Keyword("}")))
    command = Group(OneOrMore(q_obj | multi_word_names | text) + ZeroOrMore(option))
    command.ignore(comment | blank_line)
    with open(filepath) as infile:
        line_no = 1
        print "Parsing Input Configuration..."
        lines = infile.readlines()
        total_lines = len(lines)
        for line in lines:
            try:
                tmp = command.parseString(line)
                tokens = tmp.asList()
                if tokens:
                    tokens[0].append(['line_no', str(line_no)])
                result += tokens
                line_no += 1
            except Exception as exception:
                line_no += 1
                LOG.error("Parsing error: " + line)
            msg = "Parsing started..."
            if line_no <= total_lines:
                ns_util.print_progress_bar(line_no, total_lines, msg, prefix='Progress',
                                 suffix='')
        return result
开发者ID:avinetworks,项目名称:sdk,代码行数:46,代码来源:netscaler_parser.py

示例2: PartitionParser

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import ignore [as 别名]
def PartitionParser():
    start_ = Suppress('start') + Suppress('=') + Word(nums)
    size_ = Suppress('size') + Suppress('=') + Word(nums)
    id_ = Suppress('Id') + Suppress('=') + Word(nums)
    device_ = Word(alphas+nums+'/')
    comment_ = '#' + Optional(restOfLine)
    warning_ = 'Warning:' + Optional(restOfLine)
    unit_ = Literal('unit') + Optional(Suppress(':') + Word(alphas + nums)+ restOfLine)

    pinfo = start_ + Suppress(',') 
    pinfo += size_ + Suppress(',')
    pinfo += id_ + restOfLine
    partition = Group(device_ + Suppress(':') + pinfo)
    partition.ignore(comment_)
    partition.ignore(warning_)
    partition.ignore(unit_)
    #partition = ZeroOrMore(partition)
    
    return Dict(ZeroOrMore(partition))
开发者ID:BackupTheBerlios,项目名称:paella-svn,代码行数:21,代码来源:cfdisk.py

示例3: parse_pabl

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import ignore [as 别名]
    def parse_pabl(self, raw_pabl):
        INDENT = lineEnd.suppress() + empty + empty.copy().setParseAction(
            self.check_sub_indent)
        UNDENT = FollowedBy(empty).setParseAction(self.check_unindent)
        UNDENT.setParseAction(self.unindent)

        terminator = Literal(';').suppress()
        comment = Literal('#') + restOfLine
        item_name = Word(alphas, alphanums + '_')
        variable = Word(alphas, alphanums + '_.')
        variable_as = (variable + 'as' + item_name)

        stmt = Forward()
        suite = Group(
            OneOrMore(empty + stmt.setParseAction(self.check_peer_indent)))
        suite.ignore(comment)

        item_start = Literal('@item').suppress()
        item_end = Literal(':').suppress()
        permission_start = Literal('@permissions')

        item_decl = (item_start + item_name.setResultsName('item') + item_end)
        item_defn = Group(item_decl + INDENT + suite + UNDENT)

        permission_decl = (permission_start + Group(
            delimitedList(item_name).setResultsName('permissions')) + item_end)
        permission_defn = Group(permission_decl + INDENT + suite + UNDENT)

        fieldList = delimitedList(
            Group(variable_as) | variable
        ).setResultsName('fields') + terminator

        stmt << (item_defn | fieldList | Group(permission_defn))

        parseTree = suite.parseString(raw_pabl)

        return parseTree
开发者ID:PoundPay,项目名称:pabl,代码行数:39,代码来源:parser.py

示例4: processFile

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import ignore [as 别名]
def processFile(fname):
    # Set the standard items, including what to ignore
    data, fout = fOpen(fname+'.txt', 'r', fname+'.csv')
    NL, date , time = setStds()
    level, date_line, time_line, source, eventID, taskCat, info = setLines(NL, date, time)
    irrelevant_data = MatchFirst(['-','"']) + restOfLine

    # Define what a record will look like
    record = Group((level + date_line + time_line + source + eventID + taskCat + info))
    record.ignore(irrelevant_data)

    # Find records in the text file
    records = OneOrMore(record).searchString(data)

    # Write the header for the csv file - followed by each line, remove any commas from file.
    fout.write("Level,Date,Time,EventID,TaskCategory,Info\n")
    for rec in records:
        for i in rec:
            #print rec[1], rec[2]
            for index in range(len(i)):
                i[index] = i[index].replace(',','')
            fout.write("%(lvl)s, %(eDate)s, %(eTime)s, %(eID)s, %(tCat)s, %(info)s\n" % i)

    print "Processing Completed"
开发者ID:GleasonK,项目名称:Python,代码行数:26,代码来源:uBigData.py

示例5: OrderedDict

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import ignore [as 别名]
    :param string: the string from which the module has been parsed
    :param location: the index of `string` at which the parsed module starts
    :param tokens: the list of sections representing the parsed module

    :rtype: :class:`pynusmv.model.ModuleMetaClass`

    """

    from .model import ModuleMetaClass, Module as ModuleClass

    name = tokens[0]
    args = tokens[1]
    namespace = OrderedDict()
    namespace["NAME"] = name
    namespace["ARGS"] = args
    for section in tokens[2:]:
        if section.name not in namespace:
            namespace[section.name] = section.body
        else:
            update(namespace[section.name], section.body)
    return ModuleMetaClass(str(name), (ModuleClass,), namespace)


module.setParseAction(_create_module)

# Model declaration
comment = ("--" + restOfLine).suppress()
model = Group(OneOrMore(module))
model.ignore(comment)
开发者ID:xgillard,项目名称:pynusmv,代码行数:31,代码来源:parser.py

示例6: Group

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import ignore [as 别名]
# Plugin Attribute
#
attrName = nameType
attrValue = integer ^ real ^ color ^ acolor ^ nameType ^ output ^ quotedString.setParseAction(no_quotes)

pluginAttr = Group(attrName + equals + attrValue + semi)

# Plugin
#
pluginType = Word(alphanums)
pluginName = Word(alphanums + "@_")

pluginDesc = Group(pluginType + pluginName + lbrace + Group(ZeroOrMore(pluginAttr)) + rbrace).setParseAction(
    getPluginDesc
)
pluginDesc.ignore("//" + restOfLine)
pluginDesc.ignore(cStyleComment)

# Scene
#
sceneDesc = OneOrMore(pluginDesc)
sceneDesc.ignore("//" + restOfLine)
sceneDesc.ignore(cStyleComment)

nameParser = ZeroOrMore(Group(pluginType + pluginName + lbrace))
nameParser.ignore("//" + restOfLine)
nameParser.ignore(cStyleComment)


def ParseVrscene(filepath):
    return sceneDesc.parseString(open(filepath, "r").read())
开发者ID:T00N3,项目名称:T00N3Kit,代码行数:33,代码来源:parse_scene.py

示例7: parse

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import ignore [as 别名]

#.........这里部分代码省略.........
        lang.BACKGROUND('keyword') + Suppress(':') + EOL
    BACKGROUND_DEFN.setParseAction(Background)

    BACKGROUND = Group(
        BACKGROUND_DEFN('node') +
        STATEMENTS('statements')
    )
    BACKGROUND.setParseAction(Background.add_statements)

    #
    # Scenario: description
    #
    SCENARIO_DEFN = Group(
        Group(ZeroOrMore(TAG))('tags') +
        lang.SCENARIO('keyword') + Suppress(':') +
        restOfLine('name') +
        EOL
    )
    SCENARIO_DEFN.setParseAction(Scenario)

    SCENARIO = Group(
        SCENARIO_DEFN('node') +
        STATEMENTS('statements') +
        Group(ZeroOrMore(
            Suppress(lang.EXAMPLES + ':') + EOL + TABLE
        ))('outlines')
    )
    SCENARIO.setParseAction(Scenario.add_statements)

    #
    # Feature: description
    #
    FEATURE_DEFN = Group(
        Group(ZeroOrMore(TAG))('tags') +
        lang.FEATURE('keyword') + Suppress(':') +
        restOfLine('name') +
        EOL
    )
    FEATURE_DEFN.setParseAction(Feature)

    #
    # A description composed of zero or more lines, before the
    # Background/Scenario block
    #
    DESCRIPTION_LINE = Group(
        ~BACKGROUND_DEFN + ~SCENARIO_DEFN +
        OneOrMore(UTFWORD).setWhitespaceChars(' \t') +
        EOL
    )
    DESCRIPTION = Group(ZeroOrMore(DESCRIPTION_LINE | EOL))
    DESCRIPTION.setParseAction(Description)

    #
    # Complete feature file definition
    #
    FEATURE = Group(
        FEATURE_DEFN('node') +
        DESCRIPTION('description') +
        Optional(BACKGROUND('background')) +
        Group(OneOrMore(SCENARIO))('scenarios') +
        stringEnd)
    FEATURE.ignore(pythonStyleComment)
    FEATURE.setParseAction(Feature.add_blocks)

    #
    # Try parsing the string
    #

    if not token:
        token = FEATURE
    else:
        token = locals()[token]

    try:
        if string:
            tokens = token.parseString(string)
        elif filename:
            with open(filename, 'r', 'utf-8') as fp:
                tokens = token.parseFile(fp)
        else:
            raise RuntimeError("Must pass string or filename")

        return tokens
    except ParseException as e:
        if e.parserElement == stringEnd:
            msg = "Expected EOF (max one feature per file)"
        else:
            msg = e.msg

        raise LettuceSyntaxError(
            filename,
            u"{lineno}:{col} Syntax Error: {msg}\n{line}\n{space}^".format(
                msg=msg,
                lineno=e.lineno,
                col=e.col,
                line=e.line,
                space=' ' * (e.col - 1)))
    except LettuceSyntaxError as e:
        # reraise the exception with the filename
        raise LettuceSyntaxError(filename, e.string)
开发者ID:raitisdembovskis,项目名称:lettuce,代码行数:104,代码来源:parser.py

示例8: Word

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import ignore [as 别名]
            | constKwd + structArgument \
            | enumKwd + enumName + argumentName \
            | constCommonArgument \
            | commonArgument \
            | typedefName + argumentName \
            | voidKwd

funName = Word(alphas)
argumentList = Optional(delimitedList(Group(funArgument)))
# function declaration
function = Group(funReturnType).setResultsName('returnType') \
         + funName.setResultsName('functionName') \
         + '(' \
         + argumentList.setResultsName('arguments') \
         + ');'
function.ignore(cStyleComment)

# function typedef
funTypedefName = funName
funTypedef = typedefKwd \
           + Group(funReturnType).setResultsName('returnType') \
           + '(' \
           + pointerSymbol \
           + funTypedefName.setResultsName('functionName') \
           + ')' \
           + '(' \
           + argumentList.setResultsName('arguments') \
           + ');'
funTypedef.ignore(cStyleComment)
declaration = funTypedef.setResultsName('result') | 'DLL_PUBLIC' + function.setResultsName('result')
开发者ID:jstark,项目名称:revolution,代码行数:32,代码来源:makebind.py


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