本文整理汇总了Python中tokenizer.Tokenizer.peekNextToken方法的典型用法代码示例。如果您正苦于以下问题:Python Tokenizer.peekNextToken方法的具体用法?Python Tokenizer.peekNextToken怎么用?Python Tokenizer.peekNextToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tokenizer.Tokenizer
的用法示例。
在下文中一共展示了Tokenizer.peekNextToken方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestTokeniser
# 需要导入模块: from tokenizer import Tokenizer [as 别名]
# 或者: from tokenizer.Tokenizer import peekNextToken [as 别名]
class TestTokeniser(TestCase):
def setUp(self):
self.tokenizer = Tokenizer()
def test_number(self):
self.tokenizer.parse('100')
token = self.tokenizer.getNextToken()
self.assertEqual(token.NUMBER, token.type)
self.assertEqual(100, token.value)
def test_string(self):
self.tokenizer.parse('"ABC"')
token = self.tokenizer.getNextToken()
self.assertEqual(token.STRING, token.type)
self.assertEqual('ABC', token.value)
def test_peek_token(self):
self.tokenizer.parse('1+2')
token = self.tokenizer.getNextToken()
self.assertEqual(token.NUMBER, token.type)
self.assertEqual(1, token.value)
token = self.tokenizer.getNextToken()
self.assertEqual(token.OPERATOR, token.type)
self.assertEqual('+', token.value)
token = self.tokenizer.peekNextToken()
self.assertEqual(token.NUMBER, token.type)
self.assertEqual(2, token.value)
token = self.tokenizer.getNextToken()
self.assertEqual(token.NUMBER, token.type)
self.assertEqual(2, token.value)
def test_operator(self):
self.tokenizer.parse('1+2-4')
token = self.tokenizer.getNextToken()
self.assertEqual(token.NUMBER, token.type)
self.assertEqual(1, token.value)
token = self.tokenizer.getNextToken()
self.assertEqual(token.OPERATOR, token.type)
self.assertEqual('+', token.value)
token = self.tokenizer.getNextToken()
self.assertEqual(token.NUMBER, token.type)
self.assertEqual(2, token.value)
token = self.tokenizer.getNextToken()
self.assertEqual(token.OPERATOR, token.type)
self.assertEqual('-', token.value)
token = self.tokenizer.getNextToken()
self.assertEqual(token.NUMBER, token.type)
self.assertEqual(4, token.value)
def test_operator2(self):
self.tokenizer.parse('"A"+"B"')
token = self.tokenizer.getNextToken()
self.assertEqual(token.STRING, token.type)
self.assertEqual('A', token.value)
token = self.tokenizer.getNextToken()
self.assertEqual(token.OPERATOR, token.type)
self.assertEqual('+', token.value)
token = self.tokenizer.getNextToken()
self.assertEqual(token.STRING, token.type)
self.assertEqual('B', token.value)
def test_mult_operator(self):
self.tokenizer.parse('2*3')
token = self.tokenizer.getNextToken()
self.assertEqual(token.NUMBER, token.type)
self.assertEqual(2, token.value)
token = self.tokenizer.getNextToken()
self.assertEqual(token.MULTOPERATOR, token.type)
self.assertEqual('*', token.value)
token = self.tokenizer.getNextToken()
self.assertEqual(token.NUMBER, token.type)
self.assertEqual(3, token.value)
def test_mult_operator2(self):
self.tokenizer.parse('2/3')
token = self.tokenizer.getNextToken()
self.assertEqual(token.NUMBER, token.type)
self.assertEqual(2, token.value)
token = self.tokenizer.getNextToken()
#.........这里部分代码省略.........