• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import antlr3
2import testbase
3import unittest
4
5
6class t025lexerRulePropertyRef(testbase.ANTLRTest):
7    def setUp(self):
8        self.compileGrammar()
9
10
11    def testValid1(self):
12        stream = antlr3.StringStream('foobar _Ab98 \n A12sdf')
13        lexer = self.getLexer(stream)
14
15        while True:
16            token = lexer.nextToken()
17            if token.type == antlr3.EOF:
18                break
19
20        self.assertEqual(len(lexer.properties), 3, lexer.properties)
21
22        text, type, line, pos, index, channel, start, stop = lexer.properties[0]
23        self.assertEqual(text, 'foobar', lexer.properties[0])
24        self.assertEqual(type, self.lexerModule.IDENTIFIER, lexer.properties[0])
25        self.assertEqual(line, 1, lexer.properties[0])
26        self.assertEqual(pos, 0, lexer.properties[0])
27        self.assertEqual(index, -1, lexer.properties[0])
28        self.assertEqual(channel, antlr3.DEFAULT_CHANNEL, lexer.properties[0])
29        self.assertEqual(start, 0, lexer.properties[0])
30        self.assertEqual(stop, 5, lexer.properties[0])
31
32        text, type, line, pos, index, channel, start, stop = lexer.properties[1]
33        self.assertEqual(text, '_Ab98', lexer.properties[1])
34        self.assertEqual(type, self.lexerModule.IDENTIFIER, lexer.properties[1])
35        self.assertEqual(line, 1, lexer.properties[1])
36        self.assertEqual(pos, 7, lexer.properties[1])
37        self.assertEqual(index, -1, lexer.properties[1])
38        self.assertEqual(channel, antlr3.DEFAULT_CHANNEL, lexer.properties[1])
39        self.assertEqual(start, 7, lexer.properties[1])
40        self.assertEqual(stop, 11, lexer.properties[1])
41
42        text, type, line, pos, index, channel, start, stop = lexer.properties[2]
43        self.assertEqual(text, 'A12sdf', lexer.properties[2])
44        self.assertEqual(type, self.lexerModule.IDENTIFIER, lexer.properties[2])
45        self.assertEqual(line, 2, lexer.properties[2])
46        self.assertEqual(pos, 1, lexer.properties[2])
47        self.assertEqual(index, -1, lexer.properties[2])
48        self.assertEqual(channel, antlr3.DEFAULT_CHANNEL, lexer.properties[2])
49        self.assertEqual(start, 15, lexer.properties[2])
50        self.assertEqual(stop, 20, lexer.properties[2])
51
52
53if __name__ == '__main__':
54    unittest.main()
55