Skip to content

Commit

Permalink
Add support for #pragma in struct_declaration (Issue #221). (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldore authored and eliben committed Nov 22, 2017
1 parent 5da662c commit ec23318
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pycparser/c_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,11 @@ def p_struct_declaration_2(self, p):
"""
p[0] = None

def p_struct_declaration_3(self, p):
""" struct_declaration : pppragma_directive
"""
p[0] = [p[1]]

def p_struct_declarator_list(self, p):
""" struct_declarator_list : struct_declarator
| struct_declarator_list COMMA struct_declarator
Expand Down
3 changes: 3 additions & 0 deletions tests/test_c_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ def test_pragma(self):
#pragma bar
i = (a, b, c);
}
typedef struct s {
#pragma baz
} s;
''')

def test_compound_literal(self):
Expand Down
7 changes: 7 additions & 0 deletions tests/test_c_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,9 @@ def test_pragma(self):
for(;;) {}
#pragma
}
struct s {
#pragma baz
} s;
'''
s1_ast = self.parse(s1)
self.assertTrue(isinstance(s1_ast.ext[0], Pragma))
Expand All @@ -1361,6 +1364,10 @@ def test_pragma(self):
self.assertTrue(isinstance(s1_ast.ext[1].body.block_items[2], Pragma))
self.assertEqual(s1_ast.ext[1].body.block_items[2].string, '')
self.assertEqual(s1_ast.ext[1].body.block_items[2].coord.line, 6)

self.assertTrue(isinstance(s1_ast.ext[2].type.type.decls[0], Pragma))
self.assertEqual(s1_ast.ext[2].type.type.decls[0].string, 'baz')
self.assertEqual(s1_ast.ext[2].type.type.decls[0].coord.line, 9)


class TestCParser_whole_code(TestCParser_base):
Expand Down

0 comments on commit ec23318

Please sign in to comment.