當前位置: 首頁>>代碼示例>>Python>>正文


Python pyparsing.delimitedList方法代碼示例

本文整理匯總了Python中pyparsing.delimitedList方法的典型用法代碼示例。如果您正苦於以下問題:Python pyparsing.delimitedList方法的具體用法?Python pyparsing.delimitedList怎麽用?Python pyparsing.delimitedList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyparsing的用法示例。


在下文中一共展示了pyparsing.delimitedList方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _type_name_with_fields

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import delimitedList [as 別名]
def _type_name_with_fields(self):
        """Detect type name definitions.

        e.g. int v1;
                 type_t v2, v3;
        type refs ^^^^  ^^^ type_instances

        Returns:
         a list of CField() instances
        """
        return (
            self._type_reference()("type_definition")
            + self._maybe_attributes()("attributes")
            + pyparsing.delimitedList(
                self._type_instance()
            )("field")
        ).setParseAction(self._create_type_name_with_fields) 
開發者ID:google,項目名稱:rekall,代碼行數:19,代碼來源:c_parser.py

示例2: _maybe_attributes

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import delimitedList [as 別名]
def _maybe_attributes(self):
        """Possibly match some attributes.

        The syntax of attributes is described here:
        https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html
        """
        return pyparsing.Group(
            pyparsing.ZeroOrMore(
                _ATTRIBUTE
                + _DOUBLE_OPEN_PARENTHESIS
                + pyparsing.delimitedList(
                    pyparsing.Group(
                        self._identifier()("name")
                        + pyparsing.Optional(
                            _OPEN_PARENTHESIS
                            + parsers.anything_beetween("()")("args")
                            + _CLOSE_PARENTHESIS
                        )
                    )
                )
                + _DOUBLE_CLOSE_PARENTHESIS
            ).setParseAction(self._make_attribute)
        )("attributes") 
開發者ID:google,項目名稱:rekall,代碼行數:25,代碼來源:c_parser.py

示例3: expression

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import delimitedList [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

示例4: getLogLineBNF

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import delimitedList [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

示例5: _parse

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import delimitedList [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: _define_function_like

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import delimitedList [as 別名]
def _define_function_like(self):
        return (
            (_IDENTIFIER.setResultsName("name")
             + _OPEN_PARENTHESES).leaveWhitespace()
            + pyparsing.Optional(
                pyparsing.delimitedList(
                    _IDENTIFIER
                    | pyparsing.Literal("...")  # vararg macro.
                )).setResultsName("arguments")
            + _CLOSE_PARENTHESES
            + pyparsing.restOfLine.setResultsName("replacement")
        ).setParseAction(self._add_function_like) 
開發者ID:google,項目名稱:rekall,代碼行數:14,代碼來源:preprocessing_parser.py

示例7: _arguments

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import delimitedList [as 別名]
def _arguments(self):
        return pyparsing.Group(
            pyparsing.Optional(
                pyparsing.delimitedList(self.expression()))) 
開發者ID:google,項目名稱:rekall,代碼行數:6,代碼來源:macro_expander.py

示例8: gen_set

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import delimitedList [as 別名]
def gen_set(pattern_single):
    pattern_set = pp.nestedExpr(
        opener='(', closer=')',
        content=pp.delimitedList(pattern_single, delim=delim)) \
        .setParseAction(patternSetOp)
    pattern_ = pattern_single | pattern_set
    return pattern_


# define a function that can add *+! to the end 
開發者ID:uwdata,項目名稱:errudite,代碼行數:12,代碼來源:pattern_parser_operators.py

示例9: split_by_commas

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import delimitedList [as 別名]
def split_by_commas(value):
    """Split values by commas and quotes according to api-wg

    :param value: value to be split

    .. versionadded:: 3.17
    """
    word = (pp.QuotedString(quoteChar='"', escChar='\\') |
            pp.Word(pp.printables, excludeChars='",'))
    grammar = pp.stringStart + pp.delimitedList(word) + pp.stringEnd

    try:
        return list(grammar.parseString(value))
    except pp.ParseException:
        raise ValueError("Invalid value: %s" % value) 
開發者ID:openstack,項目名稱:oslo.utils,代碼行數:17,代碼來源:strutils.py

示例10: jsParse

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import delimitedList [as 別名]
def jsParse(inStr):
	# This disaster is a context-free grammar parser for parsing javascript object literals.
	# It needs to be able to handle a lot of the definitional messes you find in in-the-wild
	# javascript object literals.
	# Unfortunately, Javascript is /way/ more tolerant then JSON when it comes to object literals
	# so we can't just parse objects using python's `json` library.

	TRUE = pp.Keyword("true").setParseAction( pp.replaceWith(True) )
	FALSE = pp.Keyword("false").setParseAction( pp.replaceWith(False) )
	NULL = pp.Keyword("null").setParseAction( pp.replaceWith(None) )

	jsonString = pp.quotedString.setParseAction( pp.removeQuotes )
	jsonNumber = pp.Combine( pp.Optional('-') + ( '0' | pp.Word('123456789',pp.nums) ) +
											pp.Optional( '.' + pp.Word(pp.nums) ) +
											pp.Optional( pp.Word('eE',exact=1) + pp.Word(pp.nums+'+-',pp.nums) ) )

	jsonObject   = pp.Forward()
	jsonValue    = pp.Forward()
	jsonDict     = pp.Forward()
	jsonArray    = pp.Forward()
	jsonElements = pp.Forward()

	rawText      = pp.Regex('[a-zA-Z_$][0-9a-zA-Z_$]*')

	commaToNull = pp.Word(',,', exact=1).setParseAction(pp.replaceWith(None))
	jsonElements << pp.ZeroOrMore(commaToNull) + pp.Optional(jsonObject) + pp.ZeroOrMore((pp.Suppress(',') + jsonObject) | commaToNull)

	jsonValue << ( jsonString | jsonNumber | TRUE | FALSE | NULL )


	dictMembers = pp.delimitedList( pp.Group( (rawText | jsonString) + pp.Suppress(':') + (jsonValue | jsonDict | jsonArray)))
	jsonDict << ( pp.Dict( pp.Suppress('{') + pp.Optional(dictMembers) + pp.ZeroOrMore(pp.Suppress(',')) + pp.Suppress('}') ) )
	jsonArray << ( pp.Group(pp.Suppress('[') + pp.Optional(jsonElements) + pp.Suppress(']') ) )
	jsonObject << (jsonValue | jsonDict | jsonArray)

	jsonComment = pp.cppStyleComment
	jsonObject.ignore( jsonComment )

	def convertDict(s, l, toks):

		return dict(toks.asList())

	def convertNumbers(s,l,toks):
		n = toks[0]
		try:
			return int(n)
		except ValueError:
			return float(n)

	jsonNumber.setParseAction(convertNumbers)
	jsonDict.setParseAction(convertDict)

	# jsonObject.setDebug()
	jsonObject.parseString('"inStr"').pop()
	return jsonObject.parseString(inStr).pop()


# Stolen from http://stackoverflow.com/a/12017573/268006 
開發者ID:fake-name,項目名稱:ReadableWebProxy,代碼行數:60,代碼來源:jsLiteralParse.py


注:本文中的pyparsing.delimitedList方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。