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


Python Combine.addParseAction方法代码示例

本文整理汇总了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)
开发者ID:bizatheo,项目名称:training-material,代码行数:26,代码来源:pyparsing_block_parser.py

示例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

"""
开发者ID:bizatheo,项目名称:training-material,代码行数:33,代码来源:pyparsing_block_parser_script.py


注:本文中的pyparsing.Combine.addParseAction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。