Add support for #pragma
Preprocessor pragmas and their arguments are tokenized (as PPPRAGMA and
PPPRAGMASTR) and included in the AST as a pppragma directive with the
argument as value. If no argument was given the string will be empty.
Unit test of the lexer, parser and generator have been modified and
added accordingly.
The previous behavior, that #pragma lines would be ignored, is
henceforth obsolete.
diff --git a/tests/test_c_parser.py b/tests/test_c_parser.py
index c1bf5be..ed957dc 100755
--- a/tests/test_c_parser.py
+++ b/tests/test_c_parser.py
@@ -1284,6 +1284,21 @@
self.assertTrue(isinstance(ps2.ext[0].body.block_items[1].type.dim, Assignment))
self.assertTrue(isinstance(ps2.ext[0].body.block_items[2].type.dim, ID))
+ def test_pragma(self):
+ s1 = r'''
+ #pragma bar
+ void main() {
+ #pragma foo
+ for(;;) {}
+ }
+ '''
+ s1_ast = self.parse(s1)
+ self.assertTrue(isinstance(s1_ast.ext[0], Pragma))
+ self.assertEqual(s1_ast.ext[0].string, 'bar')
+
+ self.assertTrue(isinstance(s1_ast.ext[1].body.block_items[0], Pragma))
+ self.assertEqual(s1_ast.ext[1].body.block_items[0].string, 'foo')
+
class TestCParser_whole_code(TestCParser_base):
""" Testing of parsing whole chunks of code.
@@ -1818,6 +1833,7 @@
'''
self.assertRaises(ParseError, self.parse, s2)
+
if __name__ == '__main__':
#~ suite = unittest.TestLoader().loadTestsFromNames(
#~ ['test_c_parser.TestCParser_fundamentals.test_typedef'])