本文整理汇总了Python中pyparsing.Group.leaveWhitespace方法的典型用法代码示例。如果您正苦于以下问题:Python Group.leaveWhitespace方法的具体用法?Python Group.leaveWhitespace怎么用?Python Group.leaveWhitespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyparsing.Group
的用法示例。
在下文中一共展示了Group.leaveWhitespace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_message
# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import leaveWhitespace [as 别名]
def build_message():
global message
message = Group(Optional(Suppress(Literal(':')) + prefix + space)) + \
Group(command) + \
Group(Optional(params))
if config.getboolean('parser', 'trailing_spaces'):
message += ZeroOrMore(space)
if config.getboolean('parser', 'soft_eol'):
message += cr ^ lf ^ crlf
else:
message += crlf
message.leaveWhitespace()
示例2: Word
# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import leaveWhitespace [as 别名]
# Parser definition
# A little more complicated than is needed today, but needed to preserve
# comments in future versions.
identifier = Word(alphas, alphanums + '_-')
blank = White(' \t\n\r\f') #.leaveWhitespace()
comment = Combine(Optional(White(' \t')) + '#' + restOfLine)
comment_header = Optional(Combine(ZeroOrMore(comment | blank)), default='')
comment_inline = Optional(comment, default= '')
item = Group(comment_header + identifier + comment_inline)
section_header = comment_header + Suppress('[') + identifier + Suppress(']') + comment_inline
section_body = Group(ZeroOrMore(item))
section = Group(section_header + Optional(section_body, []))
parser = Group(ZeroOrMore(section)) + Optional(comment_header)
parser.leaveWhitespace()
def parse_INIFile(filename):
info = {}
secs, _ = parser.parseFile(filename)
for _, sec, _, items in secs:
sec = unicode(sec)
info[sec] = set()
for item in items:
_, v, _ = item
v = unicode(v)
info[sec].add(v)
return info