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


Python pyparsing.Group方法代码示例

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


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

示例1: expression

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

示例2: getLogLineBNF

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [as 别名]
def getLogLineBNF():
    global logLineBNF
    
    if logLineBNF is None:
        integer = Word( nums )
        ipAddress = delimitedList( integer, ".", combine=True )
        
        timeZoneOffset = Word("+-",nums)
        month = Word(string.uppercase, string.lowercase, exact=3)
        serverDateTime = Group( Suppress("[") + 
                                Combine( integer + "/" + month + "/" + integer +
                                        ":" + integer + ":" + integer + ":" + integer ) +
                                timeZoneOffset + 
                                Suppress("]") )
                         
        logLineBNF = ( ipAddress.setResultsName("ipAddr") + 
                       Suppress("-") +
                       ("-" | Word( alphas+nums+"@._" )).setResultsName("auth") +
                       serverDateTime.setResultsName("timestamp") + 
                       dblQuotedString.setResultsName("cmd").setParseAction(getCmdFields) +
                       (integer | "-").setResultsName("statusCode") + 
                       (integer | "-").setResultsName("numBytesSent")  + 
                       dblQuotedString.setResultsName("referrer").setParseAction(removeQuotes) +
                       dblQuotedString.setResultsName("clientSfw").setParseAction(removeQuotes) )
    return logLineBNF 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:27,代码来源:httpServerLogParser.py

示例3: _parse_filter

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [as 别名]
def _parse_filter():
        op = pyparsing.oneOf('! & |')
        lpar  = pyparsing.Literal('(').suppress()
        rpar  = pyparsing.Literal(')').suppress()

        k = pyparsing.Word(pyparsing.alphanums)
        # NOTE: We may need to expand on this list, but as this is not a real
        # LDAP server we should be OK.
        # Value to contain:
        #   numbers, upper/lower case letters, astrisk, at symbol, minus, full
        #   stop, backslash or a space
        v = pyparsing.Word(pyparsing.alphanums + "-*@.\\ äöü")
        rel = pyparsing.oneOf("= ~= >= <=")

        expr = pyparsing.Forward()
        atom = pyparsing.Group(lpar + op + expr + rpar) \
                            | pyparsing.Combine(lpar + k + rel + v + rpar)
        expr << atom + pyparsing.ZeroOrMore( expr )

        return expr 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:22,代码来源:ldap3mock.py

示例4: parse

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

示例5: _apply_modifiers

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [as 别名]
def _apply_modifiers(rule, modifiers):
        if 'grouped' in modifiers:
            rule = pp.Group(rule)

        if 'optional' in modifiers:
            rule = pp.Optional(rule)
        else:
            for modifier in modifiers:
                if modifier.startswith('at_least'):
                    times = rule_at_least.parseString(modifier)[0]
                    if times > 0:
                        rule_multiple = rule
                        for _ in range(1, times):
                            rule_multiple = rule_multiple + rule
                        rule = rule_multiple + pp.ZeroOrMore(rule)
                    else:
                        rule = pp.Optional(pp.ZeroOrMore(rule))

        return rule 
开发者ID:weso,项目名称:CWR-DataApi,代码行数:21,代码来源:rule.py

示例6: _parse

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

示例7: parse_table

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

示例8: _base_or_array_expression

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [as 别名]
def _base_or_array_expression(self):
        array_indices = pyparsing.ZeroOrMore(
            _OPEN_BRACKETS
            + self.expression
            + _CLOSE_BRACKETS
        )
        return (
            self._base_expression()
            + pyparsing.Group(array_indices)
        ).setParseAction(self._create_base_or_array_expression) 
开发者ID:google,项目名称:rekall,代码行数:12,代码来源:expression_parser.py

示例9: _arguments

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [as 别名]
def _arguments(self):
        return pyparsing.Group(
            pyparsing.Optional(pyparsing.delimitedList(self._argument()))
        ) 
开发者ID:google,项目名称:rekall,代码行数:6,代码来源:expression_parser.py

示例10: _multiword_argument

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

示例11: _enum_definition

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [as 别名]
def _enum_definition(self):
        """Detect an enum definition.

        e.g.
             enum foo {
                OPTION_1: 1 + 2,
                OPTION_2
             }
        """
        return (
            _ENUM
            + pyparsing.Optional(self._identifier())("enum_name")
            + _OPEN_CURLY
            + pyparsing.ZeroOrMore(
                pyparsing.Group(
                    self._identifier()("name")
                    + pyparsing.Optional(
                        _EQUALS
                        # This allows us to get even invalid expressions.
                        + pyparsing.SkipTo(pyparsing.Word(",}"))("expression")
                    )
                    + pyparsing.Optional(_COMMA)
                )
            )("fields")
            + _CLOSE_CURLY
            + self._maybe_attributes()("attributes")
        ).setParseAction(self._process_enum_definition) 
开发者ID:google,项目名称:rekall,代码行数:29,代码来源:c_parser.py

示例12: _arguments

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [as 别名]
def _arguments(self):
        return pyparsing.Group(
            pyparsing.Optional(
                pyparsing.delimitedList(self.expression()))) 
开发者ID:google,项目名称:rekall,代码行数:6,代码来源:macro_expander.py

示例13: meta_section

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

示例14: statement

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [as 别名]
def statement():
    return pyparsing.Group(
        _IDENTIFIER.setResultsName("lhs") + _EQUALS +
        pyparsing.Combine(
            (anything_in_curly() |
             pyparsing.QuotedString("'", escChar="\\", unquoteResults=False) |
             pyparsing.QuotedString("\"", escChar="\\", unquoteResults=False) |
             _REGEX) +
            pyparsing.ZeroOrMore(_KEYWORD),
            adjacent=False,
            joinString=" ",
        ).setResultsName("rhs")
    ) 
开发者ID:google,项目名称:rekall,代码行数:15,代码来源:yara_support.py

示例15: strings_section

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


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