Skip to content

Commit

Permalink
Remove unnecesary rule for labeled statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignacio Tiraboschi committed Jan 9, 2025
1 parent 2425174 commit 6e4322d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
4 changes: 0 additions & 4 deletions pycparser/c_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1581,10 +1581,6 @@ def p_labeled_statement_3(self, p):
p[0] = c_ast.Default([p[3]], self._token_coord(p, 1))

def p_labeled_statement_4(self, p):
""" labeled_statement : ID COLON SEMI"""
p[0] = c_ast.Label(p[1], c_ast.EmptyStatement(self._token_coord(p, 1)), self._token_coord(p, 1))

def p_labeled_statement_5(self, p):
""" labeled_statement : ID COLON """
p[0] = c_ast.Label(p[1], c_ast.EmptyStatement(self._token_coord(p, 1)), self._token_coord(p, 1))

Expand Down
16 changes: 2 additions & 14 deletions tests/test_c_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2493,25 +2493,13 @@ class TestCParser_labels(TestCParser_base):
""" Test issues related to the labels.
"""
def test_label_empty_statement(self):
# Parse the statements
# Labels with empty statements and no semicolon should be parsed correctly
s1 = r'''
int main() {
label:
}
'''
s2 = r'''
int main() {
label:;
}
'''
ast1 = self.parse(s1)
ast2 = self.parse(s2)

buf1 = io.StringIO()
buf2 = io.StringIO()
ast1.show(buf=buf1)
ast2.show(buf=buf2)
self.assertEqual(buf1.getvalue(), buf2.getvalue())
self.assertIsInstance(self.parse(s1), FileAST)

if __name__ == '__main__':
#~ suite = unittest.TestLoader().loadTestsFromNames(
Expand Down

0 comments on commit 6e4322d

Please sign in to comment.