Skip to content

Commit

Permalink
Merge pull request #108 from cod3monk/bugfix
Browse files Browse the repository at this point in the history
Fix for #107 "No coord for Prgama Node"
  • Loading branch information
eliben committed Dec 15, 2015
2 parents 904cecd + 8a17406 commit aceb9c9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pycparser/c_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,9 @@ def p_pppragma_directive(self, p):
| PPPRAGMA PPPRAGMASTR
"""
if len(p) == 3:
p[0] = c_ast.Pragma(p[2])
p[0] = c_ast.Pragma(p[2], self._coord(p.lineno(2)))
else:
p[0] = c_ast.Pragma("")
p[0] = c_ast.Pragma("", self._coord(p.lineno(1)))

# In function definitions, the declarator can be followed by
# a declaration list, for old "K&R style" function definitios.
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 @@ -1290,14 +1290,21 @@ def test_pragma(self):
void main() {
#pragma foo
for(;;) {}
#pragma
}
'''
s1_ast = self.parse(s1)
self.assertTrue(isinstance(s1_ast.ext[0], Pragma))
self.assertEqual(s1_ast.ext[0].string, 'bar')
self.assertEqual(s1_ast.ext[0].coord.line, 2)

self.assertTrue(isinstance(s1_ast.ext[1].body.block_items[0], Pragma))
self.assertEqual(s1_ast.ext[1].body.block_items[0].string, 'foo')
self.assertEqual(s1_ast.ext[1].body.block_items[0].coord.line, 4)

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)


class TestCParser_whole_code(TestCParser_base):
Expand Down

0 comments on commit aceb9c9

Please sign in to comment.