本文整理汇总了Python中pyparsing.ZeroOrMore.leaveWhitespace方法的典型用法代码示例。如果您正苦于以下问题:Python ZeroOrMore.leaveWhitespace方法的具体用法?Python ZeroOrMore.leaveWhitespace怎么用?Python ZeroOrMore.leaveWhitespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyparsing.ZeroOrMore
的用法示例。
在下文中一共展示了ZeroOrMore.leaveWhitespace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_template
# 需要导入模块: from pyparsing import ZeroOrMore [as 别名]
# 或者: from pyparsing.ZeroOrMore import leaveWhitespace [as 别名]
def parse_template(template_text):
identifier = Word(alphas, alphanums + '_')
param = Group(identifier('name') + Suppress(':') + CharsNotIn(',)')('value'))
param_list = Group(Suppress('(') + delimitedList(param, delim=',') + Suppress(')'))
benchmark_id = originalTextFor(identifier + '.' + identifier + '.' + identifier)
measurement_id = Group(benchmark_id('benchmark') + Optional(param_list('params')) + Suppress('[') + identifier('local_id') + Suppress(']'))
macro = Group(Suppress('${') + measurement_id('measurement') + Suppress('}'))
raw_text_block = originalTextFor(CharsNotIn('$'))
text = ZeroOrMore(Group(raw_text_block('text') | macro('macro')))('template')
text.leaveWhitespace()
return text.parseString(template_text).asDict()
示例2: join
# 需要导入模块: from pyparsing import ZeroOrMore [as 别名]
# 或者: from pyparsing.ZeroOrMore import leaveWhitespace [as 别名]
>>> print join(['a', 'long', 'long', 'road'])
a~long long~road
>>> print join(['very', 'long', 'phrase'])
very long~phrase
"""
if len(words) <= 2:
return tie.join(words)
else:
return (words[0] + tie_or_space(words[0], tie, space) +
space.join(words[1:-1]) +
tie + words[-1])
def format(name, format):
return NameFormat(format).format(name)
lbrace = Literal('{')
rbrace = Literal('}')
format_chars = Word(alphas)
braced_string = Forward()
braced_string << Combine(lbrace + ZeroOrMore(CharsNotIn('{}')| braced_string) + rbrace)
verbatim = Combine(ZeroOrMore(CharsNotIn(alphas + '{}') | braced_string))
delimiter = braced_string.copy().setParseAction(removeQuotes)
group = Group(Suppress(lbrace) + verbatim + format_chars + Optional(delimiter, None) +
verbatim + Suppress(rbrace))
group.setParseAction(lambda toks: NamePart(toks))
toplevel_text = CharsNotIn('{}').setParseAction(lambda toks: Text(toks))
name_format_grammar = ZeroOrMore(toplevel_text | group) + StringEnd()
name_format_grammar.leaveWhitespace()