Home | History | Annotate | Download | only in tests
      1 import antlr3
      2 import testbase
      3 import unittest
      4 
      5 
      6 class t039labels(testbase.ANTLRTest):
      7     def setUp(self):
      8         self.compileGrammar()
      9         
     10 
     11     def lexerClass(self, base):
     12         class TLexer(base):
     13             def recover(self, input, re):
     14                 # no error recovery yet, just crash!
     15                 raise
     16 
     17         return TLexer
     18     
     19         
     20     def parserClass(self, base):
     21         class TParser(base):
     22             def recover(self, input, re):
     23                 # no error recovery yet, just crash!
     24                 raise
     25 
     26         return TParser
     27     
     28         
     29     def testValid1(self):
     30         cStream = antlr3.StringStream(
     31             'a, b, c, 1, 2 A FOOBAR GNU1 A BLARZ'
     32             )
     33 
     34         lexer = self.getLexer(cStream)
     35         tStream = antlr3.CommonTokenStream(lexer)
     36         parser = self.getParser(tStream)
     37         ids, w = parser.a()
     38 
     39         assert len(ids) == 6, ids
     40         assert ids[0].text == 'a', ids[0]
     41         assert ids[1].text == 'b', ids[1]
     42         assert ids[2].text == 'c', ids[2]
     43         assert ids[3].text == '1', ids[3]
     44         assert ids[4].text == '2', ids[4]
     45         assert ids[5].text == 'A', ids[5]
     46 
     47         assert w.text == 'GNU1', w
     48 
     49 
     50 if __name__ == '__main__':
     51     unittest.main()
     52 
     53 
     54