本文整理汇总了Python中pymeta.runtime.OMetaBase类的典型用法代码示例。如果您正苦于以下问题:Python OMetaBase类的具体用法?Python OMetaBase怎么用?Python OMetaBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OMetaBase类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: test_exactly
def test_exactly(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("f")
self.assertEqual(v, "f")
self.assertEqual(e[0], 0)
开发者ID:bdauvergne,项目名称:pymeta,代码行数:11,代码来源:test_runtime.py
示例17: 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]))
try:
o.rule_digit()
except _MaybeParseError, e:
self.assertEqual(e, _MaybeParseError(1, expected("digit")))
开发者ID:bdauvergne,项目名称:pymeta,代码行数:11,代码来源:test_runtime.py
示例18: 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]))
开发者ID:jskopek,项目名称:pmtest,代码行数:11,代码来源:test_runtime.py
示例19: 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", [0, None]))
v, e = o.rule_letterOrDigit()
self.assertEqual((v, e), ("1", [1, None]))
e = self.assertRaises(ParseError, o.rule_letterOrDigit)
self.assertEqual(e, ParseError(2, expected("letter or digit")))
开发者ID:jskopek,项目名称:pmtest,代码行数:11,代码来源:test_runtime.py
示例20: 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]))
try:
o.rule_letter()
except _MaybeParseError, e:
self.assertEqual(e, _MaybeParseError(1, expected("letter")))
开发者ID:bdauvergne,项目名称:pymeta,代码行数:12,代码来源:test_runtime.py
注:本文中的pymeta.runtime.OMetaBase类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论