本文整理汇总了Python中pyparsing.Combine.addParseAction方法的典型用法代码示例。如果您正苦于以下问题:Python Combine.addParseAction方法的具体用法?Python Combine.addParseAction怎么用?Python Combine.addParseAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyparsing.Combine
的用法示例。
在下文中一共展示了Combine.addParseAction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _define_grammar
# 需要导入模块: from pyparsing import Combine [as 别名]
# 或者: from pyparsing.Combine import addParseAction [as 别名]
def _define_grammar(self):
'''define the grammar to be used, and add actions'''
self._define_actions()
eol = LineEnd().suppress()
white = Optional(White()).suppress()
begin = Keyword('begin').suppress()
end = Keyword('end').suppress()
comment = (Literal('#') + restOfLine).suppress()
data_value = Combine(OneOrMore(CharsNotIn('#\n\r')))
data_line = (LineStart() + white + Optional(data_value) +
Optional(comment) + eol)
block_name = Word(alphas, alphanums + '_')
begin_block = (LineStart() + begin + block_name +
Optional(comment) + eol)
end_block = LineStart() + end + block_name + Optional(comment) + eol
junk = ZeroOrMore(LineStart() + white + NotAny(begin) +
restOfLine + eol).suppress()
data = Group(ZeroOrMore(NotAny(end) + data_line))
block_def = begin_block + data + end_block
block_defs = junk + OneOrMore(block_def + junk)
self._grammar = block_defs
begin_block.addParseAction(self._begin_block_action)
end_block.addParseAction(self._end_block_action)
data_value.addParseAction(self._data_value_action)
示例2: LineEnd
# 需要导入模块: from pyparsing import Combine [as 别名]
# 或者: from pyparsing.Combine import addParseAction [as 别名]
eol = LineEnd().suppress()
begin = Keyword("begin").suppress()
end = Keyword("end").suppress()
comment = (Literal("#") + restOfLine).suppress()
data_value = Combine(OneOrMore(CharsNotIn("#\n\r")))
data = LineStart() + Optional(data_value) + Optional(comment) + eol
block_name = Word(alphas, alphanums + "_")
begin_block = LineStart() + begin + block_name + Optional(comment) + eol
end_block = LineStart() + end + block_name + Optional(comment) + eol
junk = ZeroOrMore(LineStart() + NotAny(begin) + restOfLine + eol).suppress()
block_def = begin_block + Group(ZeroOrMore(NotAny(end) + data)) + end_block
block_defs = junk + OneOrMore(block_def + junk)
begin_block.addParseAction(create_block)
end_block.addParseAction(finish_block)
data_value.addParseAction(handle_data)
test_str = """
bla bla
begin block_1 # bla bla
0.17 # suspicious value
# comment line
-7.34
end block_1
# and noe the second block
begin block_2
17.34
11.8
end block_2
"""