本文整理汇总了Python中ometa.runtime.OMetaBase类的典型用法代码示例。如果您正苦于以下问题:Python OMetaBase类的具体用法?Python OMetaBase怎么用?Python OMetaBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OMetaBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_listpattern
def test_listpattern(self):
"""
L{OMetaBase.rule_listpattern} matches contents of lists.
"""
o = OMetaBase([["a"]], tree=True)
v, e = o.listpattern(lambda: o.exactly("a"))
self.assertEqual((v, e), (["a"], ParseError("a", 0, None)))
示例2: 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, ParseError(o.input, 0, None)))
self.assertEqual((v, e), (True, ParseError(o.input, 0, None)))
示例3: 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", ParseError("1a", 0, None)))
exc = self.assertRaises(ParseError, o.rule_digit)
self.assertEqual(exc, ParseError(o.input, 1, expected("digit")))
示例4: 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(o.input, 3, expected(None, "o"))))
示例5: test_predFailure
def test_predFailure(self):
"""
L{OMetaBase.pred} returns True and empty error info on success.
"""
o = OMetaBase("")
with self.assertRaises(ParseError) as e:
o.pred(lambda: (False, ParseError(o.input, 0, None)))
self.assertEqual(e.exception, ParseError(o.input, 0, None))
示例6: 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", ParseError(o.input, 0, None)))
with self.assertRaises(ParseError) as e:
o.rule_letter()
self.assertEqual(e.exception, ParseError(o.input, 1, expected("letter")))
示例7: 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)
示例8: 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")
exc = self.assertRaises(ParseError, o.rule_end)
self.assertEqual(exc, ParseError(o.input, 1, None))
o.many(o.rule_anything)
self.assertEqual(o.rule_end(), (True, ParseError("abc", 3, None)))
示例9: test_tokenFailed
def test_tokenFailed(self):
"""
On failure, L{OMetaBase.rule_token} produces an error indicating the
position where match failure occurred and the expected character.
"""
data = "foozle"
o = OMetaBase(data)
with self.assertRaises(ParseError) as e:
o.rule_token("fog")
self.assertEqual(e.exception[0], 2)
self.assertEqual(e.exception[1], expected("token", "fog"))
示例10: 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)
exc = self.assertRaises(ParseError, o._not, lambda: o.exactly("x"))
self.assertEqual(exc.args[0], 1)
self.assertEqual(exc.args[1], None)
示例11: test_exactly_multi
def test_exactly_multi(self):
"""
L{OMetaBase.rule_exactly} returns the requested item from the input
string along with its position, if it's there.
"""
data = "foo"
o = OMetaBase(data)
v, e = o.rule_exactly("fo")
self.assertEqual(v, "fo")
self.assertEqual(e[0], 0)
示例12: test_letterOrDigit
def test_letterOrDigit(self):
"""
L{OMetaBase.rule_letterOrDigit} matches alphanumerics.
"""
o = OMetaBase("[email protected]")
v, e = o.rule_letterOrDigit()
self.assertEqual((v, e), ("a", ParseError(None, 0, None)))
v, e = o.rule_letterOrDigit()
self.assertEqual((v, e), ("1", ParseError(None, 1, None)))
with self.assertRaises(ParseError) as e:
o.rule_letterOrDigit()
self.assertEqual(e.exception, ParseError(o.input, 2, expected("letter or digit")))
示例13: test_orErrorTie
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]])
示例14: test_orFalseSuccess
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"))
示例15: test_anything
def test_anything(self):
"""
L{OMetaBase.rule_anything} returns each item from the input
along with its position.
"""
data = "foo"
o = OMetaBase(data)
for i, c in enumerate(data):
v, e = o.rule_anything()
self.assertEqual((c, i), (v, e[0]))