Commits

Anonymous committed b1a265c

* Added .hgignore file
* Incorporated a user patch for the do{}while statement, and added some tests of my own to verify it works

  • Participants
  • Parent commits d7ae3ce

Comments (0)

Files changed (3)

+syntax: glob
+
+*.pyc
+tests/parser.out
+tests/*tab.py
+
+
+

File pycparser/c_parser.py

         p[0] = c_ast.While(p[3], p[5], self._coord(p.lineno(1)))
     
     def p_iteration_statement_2(self, p):
-        """ iteration_statement : DO statement WHILE LPAREN expression RPAREN """
+        """ iteration_statement : DO statement WHILE LPAREN expression RPAREN SEMI """
         p[0] = c_ast.DoWhile(p[5], p[2], self._coord(p.lineno(1)))
     
     def p_iteration_statement_3(self, p):

File tests/test_c_parser.py

             'preorder' appearance) in the chunk of code is as 
             given.
         """
-        parsed = self.parse(code)
+        if isinstance(code, str):
+            parsed = self.parse(code)
+        else:
+            parsed = code
+            
         cv = self.ConstantVisitor()
         cv.visit(parsed)
         self.assertEqual(cv.values, constants)
         # declarations don't count
         self.assert_num_ID_refs(ps2, 'hash', 6)
         self.assert_num_ID_refs(ps2, 'i', 4)
+        
+        s3 = r'''
+        void x(void) {
+          int a, b;
+          if (a < b)
+            do {
+              a = 0;
+            } while (0);
+          else if (a == b) {
+            a = 1;
+          }
+        }
+        '''
+        
+        ps3 = self.parse(s3)
+        self.assert_num_klass_nodes(ps3, DoWhile, 1)
+        self.assert_num_ID_refs(ps3, 'a', 4)
+        self.assert_all_Constants(ps3, ['0', '0', '1'])
+        
 
     def test_whole_file(self):
         # See how pycparser handles a whole, real C file.