tzh
2024-08-22 c7d0944258c7d0943aa7b2211498fd612971ce27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import antlr3
import testbase
import unittest
 
 
class t037rulePropertyRef(testbase.ANTLRTest):
    def setUp(self):
        self.compileGrammar()
        
 
    def lexerClass(self, base):
        class TLexer(base):
            def recover(self, input, re):
                # no error recovery yet, just crash!
                raise
 
        return TLexer
    
        
    def parserClass(self, base):
        class TParser(base):
            def recover(self, input, re):
                # no error recovery yet, just crash!
                raise
 
        return TParser
    
        
    def testValid1(self):
        cStream = antlr3.StringStream('   a a a a  ')
 
        lexer = self.getLexer(cStream)
        tStream = antlr3.CommonTokenStream(lexer)
        parser = self.getParser(tStream)
        start, stop, text = parser.a().bla
 
        # first token of rule b is the 2nd token (counting hidden tokens)
        assert start.index == 1, start
        
        # first token of rule b is the 7th token (counting hidden tokens)
        assert stop.index == 7, stop
 
        assert text == "a a a a", text
 
 
if __name__ == '__main__':
    unittest.main()