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


Python pyparsing.OneOrMore方法代码示例

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


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

示例1: _element

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import OneOrMore [as 别名]
def _element(self):
        """The parser for all elements."""
        self.element = pyparsing.Forward()
        self.element << (
            (~_TYPEDEF) + (
                # e.g. int x;
                self._type_name_with_fields()

                # e.g. struct s {};
                | self._struct_definition_possibly_with_fields()

                # e.g. enum foo { OPTION = 1 + 2; };
                | self._enum_definition()

                | pyparsing.OneOrMore(_SEMICOLON)
            )
        )
        return self.element.setName("element") 
开发者ID:google,项目名称:rekall,代码行数:20,代码来源:c_parser.py

示例2: expression

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import OneOrMore [as 别名]
def expression(self):
        expression = pyparsing.Forward()

        # (1 + (2 + 3))
        nested_expression = pyparsing.nestedExpr(
            "(", ")", expression).setParseAction(self._combine_lists)

        # FOO(2 , 3)
        function_call = (
            _TOKEN().setResultsName("function")
            + _OPEN_PARENTHESIS()
            + pyparsing.delimitedList(
                pyparsing.Combine(expression, adjacent=False, joinString=" "),
                delim=",").setResultsName("func_args")
            + _CLOSE_PARENTHESIS()
        )

        expression << pyparsing.OneOrMore(
            function_call.setParseAction(self._is_known_function)
            | pyparsing.Group(nested_expression)
            | _TOKEN()
            | _NOT_TOKEN()
        )

        return pyparsing.Combine(expression, adjacent=False, joinString=" ") 
开发者ID:google,项目名称:rekall,代码行数:27,代码来源:macro_expander.py

示例3: parse

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import OneOrMore [as 别名]
def parse(input_string):
        word = Word(alphanums)
        command = Group(OneOrMore(word))
        token = Suppress("->")
        device = Group(OneOrMore(word))
        argument = Group(OneOrMore(word))
        event = command + token + device + Optional(token + argument)
        parse_results = event.parseString(input_string)
        cmd = parse_results[0]
        dev = parse_results[1]
        cmd_str = "_".join(cmd)
        dev_str = "_".join(dev)
        try:
            val = parse_results[2]
        except IndexError:
            val_str = None
        else:
            val_str = "_".join(val)
        return cmd_str, dev_str, val_str 
开发者ID:jackdbd,项目名称:design-patterns,代码行数:21,代码来源:interpreter.py

示例4: grammar

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import OneOrMore [as 别名]
def grammar():
    parenthesis = Forward()
    parenthesis <<= "(" + ZeroOrMore(CharsNotIn("()") | parenthesis) + ")"

    field_def = OneOrMore(Word(alphanums + "_\"'`:-") | parenthesis)
    field_def.setParseAction(field_act)

    tablename_def = ( Word(alphas + "`_") | QuotedString("\"") )

    field_list_def = field_def + ZeroOrMore(Suppress(",") + field_def)
    field_list_def.setParseAction(field_list_act)

    create_table_def = Literal("CREATE") + "TABLE" + tablename_def.setResultsName("tableName") + "(" + field_list_def.setResultsName("fields") + ")" + ";"
    create_table_def.setParseAction(create_table_act)

    add_fkey_def = Literal("FOREIGN") + "KEY" + "(" + Word(alphanums).setResultsName("keyName") + ")" + "REFERENCES" + Word(alphanums).setResultsName("fkTable") + "(" + Word(alphanums + "_").setResultsName("fkCol") + ")" + Optional(Literal("DEFERRABLE")) + ";"
    add_fkey_def.setParseAction(add_fkey_act)

    other_statement_def = OneOrMore(CharsNotIn(";")) + ";"
    other_statement_def.setParseAction(other_statement_act)

    comment_def = "--" + ZeroOrMore(CharsNotIn("\n"))
    comment_def.setParseAction(other_statement_act)

    return OneOrMore(comment_def | create_table_def | add_fkey_def | other_statement_def) 
开发者ID:LGE-ARC-AdvancedAI,项目名称:auptimizer,代码行数:27,代码来源:sql_graphviz.py

示例5: _parse

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import OneOrMore [as 别名]
def _parse(mystr):

    LBRACE, RBRACE, EQUAL = map(pp.Suppress, "{}=")
    field = pp.Word(pp.printables + ' ', excludeChars='[]=')
    field.addParseAction(pp.tokenMap(str.rstrip))
    string = pp.dblQuotedString().setParseAction(pp.removeQuotes)
    number = pp.pyparsing_common.number()
    date_expr = pp.Regex(r'\d\d\d\d-\d\d-\d\d')
    time_expr = pp.Regex(r'\d\d:\d\d:\d\d\.\d\d\d')
    nan = pp.Keyword('nan')
    scalar_value = (string | date_expr | time_expr | number | nan)

    list_marker = pp.Suppress("[]")
    value_list = pp.Forward()
    jobject = pp.Forward()

    memberDef1 = pp.Group(field + EQUAL + scalar_value)
    memberDef2 = pp.Group(field + EQUAL + jobject)
    memberDef3 = pp.Group(field + list_marker + EQUAL + LBRACE + value_list +
                          RBRACE)
    memberDef = memberDef1 | memberDef2 | memberDef3

    value_list <<= (pp.delimitedList(scalar_value, ",") |
                    pp.ZeroOrMore(pp.Group(pp.Dict(memberDef2))))
    value_list.setParseAction(lambda t: [pp.ParseResults(t[:])])

    members = pp.OneOrMore(memberDef)
    jobject <<= pp.Dict(LBRACE + pp.ZeroOrMore(memberDef) + RBRACE)
    # force empty jobject to be a dict
    jobject.setParseAction(lambda t: t or {})

    parser = members
    parser = pp.OneOrMore(pp.Group(pp.Dict(memberDef)))

    return parser.parseString(mystr) 
开发者ID:matthewgilbert,项目名称:pdblp,代码行数:37,代码来源:parser.py

示例6: OperationsSchema

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import OneOrMore [as 别名]
def OperationsSchema(v):
    if isinstance(v, six.text_type):
        try:
            v = pyparsing.OneOrMore(
                pyparsing.nestedExpr()).parseString(v).asList()[0]
        except pyparsing.ParseException as e:
            api.abort(400, {"cause": "Invalid operations",
                            "reason": "Fail to parse the operations string",
                            "detail": six.text_type(e)})
    return voluptuous.Schema(voluptuous.Any(*OperationsSchemaBase),
                             required=True)(v) 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:13,代码来源:api.py

示例7: parse

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import OneOrMore [as 别名]
def parse(self, flags):
        _flags = []
        for k, v in flags.items():
            if v == True:
                _flags.append(k)
            elif v in [False, None]:
                pass
            else:
                _flags.append(k + "_" + v)

        def cb_conditional(s, l, t):
            if (t.cond in _flags) != (t.negate == "!"):
                return t.expr
            else:
                return []

        word = Word(alphanums + ":<>.[]_-,=~/^~")
        conditional = Forward()
        conditional << (
            Optional("!")("negate")
            + word("cond")
            + Suppress("?")
            + Suppress("(")
            + OneOrMore(conditional ^ word)("expr")
            + Suppress(")")
        ).setParseAction(cb_conditional)
        string = word
        string_list = OneOrMore(conditional ^ string)
        s = " ".join(string_list.parseString(self.__str__()))
        logger.debug(
            "Parsing '{}' with flags {} => {}".format(self.__str__(), str(_flags), s)
        )
        return s 
开发者ID:olofk,项目名称:fusesoc,代码行数:35,代码来源:core.py

示例8: _make_matcher_element

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import OneOrMore [as 别名]
def _make_matcher_element(self):
        # Define an extra parse action for the child's matcher element.
        def f(tokens):
            if tokens.asList():
                # Add current match values to the _repetitions_matched list.
                self._repetitions_matched.append(save_current_matches(self.child))

                # Wipe current match values for the next repetition (if any).
                self.child.reset_for_new_match()
            return tokens

        # Get the child's matcher element and add the extra parse action.
        child_element = self.child.matcher_element.addParseAction(f)

        # Determine the parser element type to use.
        type_ = pyparsing.ZeroOrMore if self.is_optional else pyparsing.OneOrMore

        # Handle the special case of a repetition ancestor, e.g. ((a b)+)+
        rep = self.repetition_ancestor
        if rep:
            # Check if there are no other branches.
            c = rep.child
            only_branch = True
            while c is not self:
                if len(c.children) > 1:
                    only_branch = False
                    break
                else:
                    c = c.children[0]

            # Use an And element instead if self is the only branch because
            # it makes no sense to repeat a repeat like this!
            if only_branch:
                type_ = pyparsing.And
                child_element = [child_element]

        return self._set_matcher_element_attributes(type_(child_element)) 
开发者ID:Danesprite,项目名称:pyjsgf,代码行数:39,代码来源:expansions.py

示例9: parse_table

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import OneOrMore [as 别名]
def parse_table(attribute, string):
    Line = OneOrMore(Float)('data') + Literal(';') + Optional(Comments, default='')('name')
    Grammar = Suppress(Keyword('mpc.{}'.format(attribute)) + Keyword('=') + Keyword('[') + Optional(Comments)) + OneOrMore(Group(Line)) + Suppress(Keyword(']') + Optional(Comments))

    result, i, j = Grammar.scanString(string).next()

    _list = list()
    for r in result:
        _list.append([int_else_float_except_string(s) for s in r['data'].asList()])

    return _list 
开发者ID:power-system-simulation-toolbox,项目名称:psst,代码行数:13,代码来源:case_parser.py

示例10: static_function

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import OneOrMore [as 别名]
def static_function(self):
        return (
            (pyparsing.Keyword("static") | pyparsing.Keyword("inline"))
            + pyparsing.OneOrMore(pyparsing.Word(pyparsing.alphanums + "_*&"))
            + parsers.anything_in_parentheses()
            + parsers.anything_in_curly()
        ).suppress() 
开发者ID:google,项目名称:rekall,代码行数:9,代码来源:preprocessing_parser.py

示例11: _multiword_argument

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import OneOrMore [as 别名]
def _multiword_argument(self):
        return pyparsing.Group(
            self._variable()
            + pyparsing.OneOrMore(self._variable())
        ).setParseAction(util.action(pre_ast.CompositeBlock)) 
开发者ID:google,项目名称:rekall,代码行数:7,代码来源:expression_parser.py

示例12: meta_section

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import OneOrMore [as 别名]
def meta_section():
    return pyparsing.Group(
        pyparsing.Literal("meta") +
        _COLON +
        pyparsing.OneOrMore(
            statement()
        ).setResultsName("statements")
    ).setResultsName("meta") 
开发者ID:google,项目名称:rekall,代码行数:10,代码来源:yara_support.py

示例13: rule

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import OneOrMore [as 别名]
def rule():
    return (_RULE +
            _IDENTIFIER.setResultsName("name") +
            _LEFT_CURLY +
            pyparsing.OneOrMore(section()) +
            _RIGHT_CURLY) 
开发者ID:google,项目名称:rekall,代码行数:8,代码来源:yara_support.py

示例14: yara_parser

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import OneOrMore [as 别名]
def yara_parser():
    return pyparsing.OneOrMore(rule()) 
开发者ID:google,项目名称:rekall,代码行数:4,代码来源:yara_support.py

示例15: _globalParse___aaa_attributes

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import OneOrMore [as 别名]
def _globalParse___aaa_attributes(line, type, count_aaa):
    aaa_dict = {}

    authentication_list    = (Suppress('login')                     + Word(printables))  ('authent_list')
    authentication_groups  = (OneOrMore(Optional(Suppress('group')) + Word(printables))) ('authent_methods')

    parse_authentication   = authentication_list + authentication_groups

    # parse_authorization_options  = MatchFirst(['exec', 'login']) + Word(printables) + OneOrMore(Optional(Suppress('group')) + Word(printables))

    accounting_login   = (MatchFirst(['exec', 'network', 'connection', 'commands'])) ('acc_login')
    accounting_list    = (Optional(Word(nums)) + Word(printables))                   ('acc_list')
    accounting_record  = (MatchFirst(['start-stop', 'stop-only', 'stop']))           ('acc_record')
    accounting_methods = (OneOrMore(Optional(Suppress('group')) + Word(printables))) ('acc_methods')

    parse_accounting   = accounting_login + accounting_list + accounting_record + accounting_methods

    if   type == 'authentication':
        result = parse_authentication.parseString(line)
        aaa_dict.update({'login' + str(count_aaa): {}})
        aaa_dict['login' + str(count_aaa)]['list']    = result.authent_list[0]
        aaa_dict['login' + str(count_aaa)]['methods'] = result.authent_methods.asList()
    # elif type == 'authorization':
    #     result = parse_authorization_options.parseString(line)
    #     aaa_dict.update({'login' + str(count_aaa): {}})
    #     aaa_dict['login' + str(count_aaa)]['login']   = result.pop(0)
    #     aaa_dict['login' + str(count_aaa)]['list']    = result.pop(0)
    #     aaa_dict['login' + str(count_aaa)]['methods'] = result.asList()
    elif type == 'accounting':
        result = parse_accounting.parseString(line)
        aaa_dict.update({'login' + str(count_aaa): {}})
        aaa_dict['login' + str(count_aaa)]['login']   = result.acc_login
        aaa_dict['login' + str(count_aaa)]['list']    = result.acc_list.asList()
        aaa_dict['login' + str(count_aaa)]['record']  = result.acc_record
        aaa_dict['login' + str(count_aaa)]['methods'] = result.acc_methods.asList()

    return aaa_dict 
开发者ID:cisco-config-analysis-tool,项目名称:ccat,代码行数:39,代码来源:aaa.py


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