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


Python runtime.OMetaBase类代码示例

本文整理汇总了Python中pymeta.runtime.OMetaBase的典型用法代码示例。如果您正苦于以下问题:Python OMetaBase类的具体用法?Python OMetaBase怎么用?Python OMetaBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了OMetaBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: findInGrammar

 def findInGrammar(self, expr):
     """
     L{OMeta.pythonExpr()} can extract a single Python expression from a
     string, ignoring the text following it.
     """
     o = OMetaBase(expr + "\nbaz ::= ...\n")
     self.assertEqual(o.pythonExpr()[0][0], expr)
开发者ID:thepian,项目名称:themaestro,代码行数:7,代码来源:test_pymeta.py

示例2: test_listpattern

 def test_listpattern(self):
     """
     L{OMetaBase.rule_listpattern} matches contents of lists.
     """
     o = OMetaBase([["a"]])
     v, e = o.listpattern(lambda: o.exactly("a"))
     self.assertEqual((v, e), (["a"], [0, None]))
开发者ID:bdauvergne,项目名称:pymeta,代码行数:7,代码来源:test_runtime.py

示例3: test_consumed_by

 def test_consumed_by(self):
     """
     L{OMetaBase.consumed_by} return the full matched string, not each matched parts
     """
     o = OMetaBase("aax")
     v, e = o.consumed_by(lambda: o.many(lambda: o.exactly("a")))
     self.assertEqual((v, e), ("aa", _MaybeParseError(2, [('expected', None, 'a')])))
开发者ID:bdauvergne,项目名称:pymeta,代码行数:7,代码来源:test_runtime.py

示例4: test_range

 def test_range(self):
     """
     L{OMetaBase.range} matches range of characters
     """
     o = OMetaBase("2")
     v, e = o.range('0', '9')
     self.assertEqual((v, e), ("2", [0, None]))
开发者ID:bdauvergne,项目名称:pymeta,代码行数:7,代码来源:test_runtime.py

示例5: test_predSuccess

    def test_predSuccess(self):
        """
        L{OMetaBase.pred} returns True and empty error info on success.
        """

        o = OMetaBase("")
        v, e = o.pred(lambda: (True, _MaybeParseError(0, None)))
        self.assertEqual((v, e), (True, _MaybeParseError(0, None)))
开发者ID:bdauvergne,项目名称:pymeta,代码行数:8,代码来源:test_runtime.py

示例6: test_keyword

    def test_keyword(self):
        """
        L{OMetaBase.rule_keyword} matches all the characters in the given string.
        """

        o = OMetaBase("foo bar")
        v, e = o.rule_keyword("foo")
        self.assertEqual(v, { 'keyword':"foo", 'prefix':[] })
开发者ID:thepian,项目名称:themaestro,代码行数:8,代码来源:test_runtime.py

示例7: test_digit

 def test_digit(self):
     """
     L{OMetaBase.rule_digit} matches digits.
     """
     o = OMetaBase("1a")
     v, e = o.rule_digit()
     self.assertEqual((v, e), ("1", [0, None]))
     e = self.assertRaises(ParseError, o.rule_digit)
     self.assertEqual(e, ParseError(1, expected("digit")))
开发者ID:jskopek,项目名称:pmtest,代码行数:9,代码来源:test_runtime.py

示例8: test_many

    def test_many(self):
        """
        L{OMetaBase.many} returns a list of parsed values and the error that
        caused the end of the loop.
        """

        data = "ooops"
        o  = OMetaBase(data)
        self.assertEqual(o.many(lambda: o.rule_exactly('o')), (['o'] * 3, ParseError(3, expected(None, 'o'))))
开发者ID:jskopek,项目名称:pmtest,代码行数:9,代码来源:test_runtime.py

示例9: test_letter

    def test_letter(self):
        """
        L{OMetaBase.rule_letter} matches letters.
        """

        o = OMetaBase("a1")
        v, e = o.rule_letter()
        self.assertEqual((v, e), ("a", [0, None]))
        e = self.assertRaises(ParseError, o.rule_letter)
        self.assertEqual(e, ParseError(1, expected("letter")))
开发者ID:jskopek,项目名称:pmtest,代码行数:10,代码来源:test_runtime.py

示例10: test_end

 def test_end(self):
     """
     L{OMetaBase.rule_end} matches the end of input and raises L{ParseError}
     if input is left.
     """
     o = OMetaBase("abc")
     e = self.assertRaises(ParseError, o.rule_end)
     self.assertEqual(e, ParseError(1, None))
     o.many(o.rule_anything)
     self.assertEqual(o.rule_end(), (True, [3, None]))
开发者ID:jskopek,项目名称:pmtest,代码行数:10,代码来源:test_runtime.py

示例11: test_notError

    def test_notError(self):
        """
        When L{OMetaBase._not} fails, its error contains the current input position and no error info.
        """

        data = "xy"
        o = OMetaBase(data)
        e = self.assertRaises(ParseError, o._not, lambda: o.exactly("x"))
        self.assertEqual(e[0], 1)
        self.assertEqual(e[1], None)
开发者ID:jskopek,项目名称:pmtest,代码行数:10,代码来源:test_runtime.py

示例12: test_spaces

    def test_spaces(self):
        """
        L{OMetaBase.rule_spaces} provides error information.
        """

        data = "  xyz"
        o = OMetaBase(data)
        v, e = o.rule_spaces()

        self.assertEqual(e[0], 2)
开发者ID:bdauvergne,项目名称:pymeta,代码行数:10,代码来源:test_runtime.py

示例13: test_end

 def test_end(self):
     """
     L{OMetaBase.rule_end} matches the end of input and raises L{_MaybeParseError}
     if input is left.
     """
     o = OMetaBase("abc")
     try:
         o.rule_end()
     except _MaybeParseError, e:
         self.assertEqual(e, _MaybeParseError(1, None))
开发者ID:bdauvergne,项目名称:pymeta,代码行数:10,代码来源:test_runtime.py

示例14: test_predFailure

    def test_predFailure(self):
        """
        L{OMetaBase.pred} returns True and empty error info on success.
        """

        o = OMetaBase("")
        try:
            o.pred(lambda: (False, _MaybeParseError(0, None)))
        except _MaybeParseError, e:
            self.assertEqual(e, _MaybeParseError(0, None))
开发者ID:bdauvergne,项目名称:pymeta,代码行数:10,代码来源:test_runtime.py

示例15: test_interleave

 def test_interleave(self):
     """
     L{OMetaBase.interleave} matched randomly mixed parts
     """
     o = OMetaBase("ab")
     d = dict()
     v, e = o._interleave(d, '1', lambda: o.exactly('a'), None, '*', lambda: o.exactly('b'), 'x')
     self.assertEqual((v, e), (['a', ['b']], [1, None]))
     self.assertIn('x', d)
     self.assertEqual(d['x'], ['b'])
开发者ID:bdauvergne,项目名称:pymeta,代码行数:10,代码来源:test_runtime.py


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