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


Python pyparsing.replaceWith方法代码示例

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


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

示例1: _wrap_as_optional_numeric

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import replaceWith [as 别名]
def _wrap_as_optional_numeric(self, field, name, columns):
        # Regular expression accepting as many whitespaces as columns
        field_empty = pp.Regex('[0]{' + str(columns) + '}')

        resultsName = field.resultsName

        field_empty.setName(name)

        # Whitespaces are not removed
        field_empty.leaveWhitespace()

        # None is returned by this rule
        field_empty.setParseAction(pp.replaceWith(None))

        field_empty = field_empty.setResultsName(field.resultsName)

        field = field | field_empty

        field.setName(name)
        field = field.setResultsName(resultsName)

        field.leaveWhitespace()

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

示例2: _match_boolean

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import replaceWith [as 别名]
def _match_boolean(literal):
    return (
        literal
        + pyparsing.Empty().setParseAction(pyparsing.replaceWith("="))
        + pyparsing.Empty().setParseAction(pyparsing.replaceWith(True))
    ) 
开发者ID:Mergifyio,项目名称:mergify-engine,代码行数:8,代码来源:parser.py

示例3: fixto

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import replaceWith [as 别名]
def fixto(output, item):
    """Forces an item to result in a specific output."""
    return _coconut_tail_call(attach, replaceWith(output), item) 
开发者ID:evhub,项目名称:pyprover,代码行数:5,代码来源:parser.py

示例4: make_integer_word_expr

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import replaceWith [as 别名]
def make_integer_word_expr(int_name, int_value):
    return pp.CaselessKeyword(int_name).addParseAction(pp.replaceWith(int_value)) 
开发者ID:pyparsing,项目名称:pyparsing,代码行数:4,代码来源:delta_time.py

示例5: plural

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import replaceWith [as 别名]
def plural(s):
    return CK(s) | CK(s + "s").addParseAction(pp.replaceWith(s)) 
开发者ID:pyparsing,项目名称:pyparsing,代码行数:4,代码来源:delta_time.py

示例6: makeLit

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import replaceWith [as 别名]
def makeLit(s, val):
    ret = pp.CaselessLiteral(s)
    return ret.setParseAction(pp.replaceWith(val)) 
开发者ID:pyparsing,项目名称:pyparsing,代码行数:5,代码来源:wordsToNum.py

示例7: make_keyword

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import replaceWith [as 别名]
def make_keyword(kwd_str, kwd_value):
    return pp.Keyword(kwd_str).setParseAction(pp.replaceWith(kwd_value)) 
开发者ID:pyparsing,项目名称:pyparsing,代码行数:4,代码来源:jsonParser.py

示例8: romanNumeralLiteral

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import replaceWith [as 别名]
def romanNumeralLiteral(numeralString, value):
    return pp.Literal(numeralString).setParseAction(pp.replaceWith(value)) 
开发者ID:pyparsing,项目名称:pyparsing,代码行数:4,代码来源:romanNumerals.py

示例9: _wrap_as_optional

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import replaceWith [as 别名]
def _wrap_as_optional(self, field, name, columns):
        """
        Adds a wrapper rule to the field to accept empty strings.

        This empty string should be of the same size as the columns parameter.
        One smaller or bigger will be rejected.

        This wrapper will return None if the field is empty.

        :param field: the field to wrap
        :param name: name of the field
        :param columns: number of columns it takes
        :return: the field with an additional rule to allow empty strings
        """
        # Regular expression accepting as many whitespaces as columns
        field_empty = pp.Regex('[ ]{' + str(columns) + '}')

        resultsName = field.resultsName

        field_empty.setName(name)

        # Whitespaces are not removed
        field_empty.leaveWhitespace()

        # None is returned by this rule
        field_empty.setParseAction(pp.replaceWith(None))

        field_empty = field_empty.setResultsName(resultsName)

        field = field | field_empty

        field.setName(name)
        field = field.setResultsName(resultsName)

        field.leaveWhitespace()

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

示例10: audio_visual_key

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import replaceWith [as 别名]
def audio_visual_key(name=None):
    """
    Creates the grammar for an Audio Visual Key code.

    This is a variation on the ISAN (International Standard Audiovisual Number)

    :param name: name for the field
    :return: grammar for an ISRC field
    """

    if name is None:
        name = 'AVI Field'

    society_code = basic.numeric(3)
    society_code = society_code.setName('Society Code') \
        .setResultsName('society_code')

    av_number = basic.alphanum(15, extended=True, isLast=True)
    field_empty = pp.Regex('[ ]{15}')
    field_empty.setParseAction(pp.replaceWith(''))
    av_number = av_number | field_empty
    av_number = av_number.setName('Audio-Visual Number') \
        .setResultsName('av_number')

    field = pp.Group(society_code + pp.Optional(av_number))

    field.setParseAction(lambda v: _to_avi(v[0]))

    field = field.setName(name)

    return field.setResultsName('audio_visual_key') 
开发者ID:weso,项目名称:CWR-DataApi,代码行数:33,代码来源:special.py

示例11: jsParse

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import replaceWith [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.replaceWith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。