當前位置: 首頁>>代碼示例>>Python>>正文


Python OMetaBase._or方法代碼示例

本文整理匯總了Python中ometa.runtime.OMetaBase._or方法的典型用法代碼示例。如果您正苦於以下問題:Python OMetaBase._or方法的具體用法?Python OMetaBase._or怎麽用?Python OMetaBase._or使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ometa.runtime.OMetaBase的用法示例。


在下文中一共展示了OMetaBase._or方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_orSimpleFailure

# 需要導入模塊: from ometa.runtime import OMetaBase [as 別名]
# 或者: from ometa.runtime.OMetaBase import _or [as 別名]
    def test_orSimpleFailure(self):
        """
        When none of the alternatives passed to L{OMetaBase._or} succeed, the
        one that got the furthest is returned.
        """

        data = "foozle"
        o = OMetaBase(data)

        with self.assertRaises(ParseError) as e:
            o._or([lambda: o.token("fog"), lambda: o.token("foozik"), lambda: o.token("woozle")])
        self.assertEqual(e.exception[0], 4)
        self.assertEqual(e.exception[1], expected("token", "foozik"))
開發者ID:jballard1991,項目名稱:software,代碼行數:15,代碼來源:test_runtime.py

示例2: test_orErrorTie

# 需要導入模塊: from ometa.runtime import OMetaBase [as 別名]
# 或者: from ometa.runtime.OMetaBase import _or [as 別名]
    def test_orErrorTie(self):
        """
        When branches of L{OMetaBase._or} produce errors that tie for rightmost
        position, they are merged.
        """

        data = "foozle"
        o = OMetaBase(data)

        v, e = o._or([lambda: o.token("fog"), lambda: o.token("foz"), lambda: o.token("f")])
        self.assertEqual(e[0], 2)
        self.assertEqual(e[1], [expected("token", "fog")[0], expected("token", "foz")[0]])
開發者ID:jballard1991,項目名稱:software,代碼行數:14,代碼來源:test_runtime.py

示例3: test_orFalseSuccess

# 需要導入模塊: from ometa.runtime import OMetaBase [as 別名]
# 或者: from ometa.runtime.OMetaBase import _or [as 別名]
    def test_orFalseSuccess(self):
        """
        When a failing branch of L{OMetaBase._or} gets further than a
        succeeding one, its error is returned instead of the success branch's.
        """

        data = "foozle"
        o = OMetaBase(data)

        v, e = o._or([lambda: o.token("fog"), lambda: o.token("foozik"), lambda: o.token("f")])
        self.assertEqual(e[0], 4)
        self.assertEqual(e[1], expected("token", "foozik"))
開發者ID:jballard1991,項目名稱:software,代碼行數:14,代碼來源:test_runtime.py

示例4: test_or

# 需要導入模塊: from ometa.runtime import OMetaBase [as 別名]
# 或者: from ometa.runtime.OMetaBase import _or [as 別名]
    def test_or(self):
        """
        L{OMetaBase._or} returns the result of the first of its
        arguments to succeed.
        """

        data = "a"

        o = OMetaBase(data)
        called = [False, False, False]
        targets = ['b', 'a', 'c']
        matchers = []
        for i, m in enumerate(targets):
            def match(i=i, m=m):
                called[i] = True
                return o.exactly(m)
            matchers.append(match)

        v, e = o._or(matchers)
        self.assertEqual(called, [True, True, False])
        self.assertEqual(v, 'a')
        self.assertEqual(e.args[0], 0)
開發者ID:abenassi,項目名稱:parsley,代碼行數:24,代碼來源:test_runtime.py


注:本文中的ometa.runtime.OMetaBase._or方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。