state.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:NeoVintageous 作者: NeoVintageous 项目源码 文件源码
def expect_match(self, pattern, on_error=None):
        """
        Require @item to match at the current `position`.

        Raises a ValueError if @item does not match.

        @pattern
          A regular expression.

        @on_error
          A function that returns an error. The error returned overrides the
          default ValueError.
        """
        m = re.compile(pattern).match(self.source, self.position)
        if m:
            self.position += m.end() - m.start()

            return m

        if not on_error:
            raise ValueError('expected match with \'{0}\', at \'{1}\''.format(pattern, self.source[self.position:]))

        raise on_error()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号