diff options
-rw-r--r-- | .hgignore | 8 | ||||
-rw-r--r-- | pycparser/c_parser.py | 2 | ||||
-rw-r--r-- | tests/test_c_parser.py | 25 |
3 files changed, 33 insertions, 2 deletions
diff --git a/.hgignore b/.hgignore new file mode 100644 index 0000000..c3f6f75 --- /dev/null +++ b/.hgignore @@ -0,0 +1,8 @@ +syntax: glob + +*.pyc +tests/parser.out +tests/*tab.py + + + diff --git a/pycparser/c_parser.py b/pycparser/c_parser.py index 8e75519..11115f5 100644 --- a/pycparser/c_parser.py +++ b/pycparser/c_parser.py @@ -996,7 +996,7 @@ class CParser(PLYParser): 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):
diff --git a/tests/test_c_parser.py b/tests/test_c_parser.py index d57d8ee..20667ac 100644 --- a/tests/test_c_parser.py +++ b/tests/test_c_parser.py @@ -860,7 +860,11 @@ class TestCParser_whole_code(unittest.TestCase): '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) @@ -972,6 +976,25 @@ class TestCParser_whole_code(unittest.TestCase): # 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. |