diff --git a/wrap/Module.cpp b/wrap/Module.cpp index bfb6a3145..bc2bc5afe 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -160,14 +160,14 @@ Module::Module(const string& interfacePath, Rule namespace_name_p = lexeme_d[(upper_p | lower_p) >> *(alnum_p | '_')]; - Rule namespace_p = str_p("namespace") >> - namespace_name_p[assign_a(namespaces_parent, namespaces)][push_back_a(namespaces)] // save previous state - >> confix_p('{', // start namespace - +(comments_p | class_p | namespace_p), - ('}' >> (*anychar_p - ch_p(';'))) // end namespace, avoid confusion with classes - )[assign_a(namespaces, namespaces_parent)]; // switch back to parent namespace + Rule namespace_p = str_p("namespace") >> + namespace_name_p[assign_a(namespaces_parent, namespaces)][push_back_a(namespaces)] // save previous state + >> ch_p('{') >> + *(class_p | namespace_p | comments_p) >> + str_p("}//\\namespace") // end namespace, avoid confusion with classes + [assign_a(namespaces, namespaces_parent)]; // switch back to parent namespace - Rule module_content_p = comments_p | namespace_p | class_p; + Rule module_content_p = comments_p | class_p | namespace_p ; Rule module_p = *module_content_p >> !end_p; diff --git a/wrap/tests/geometry.h b/wrap/tests/geometry.h index 843190e5c..c6d770e5e 100644 --- a/wrap/tests/geometry.h +++ b/wrap/tests/geometry.h @@ -22,6 +22,9 @@ class Point3 { // another comment +// NOTE: you *must* end namespaces as follows: +}//\namespace + // another comment /** @@ -71,8 +74,6 @@ class Test { // even more comments at the end! }; -} // \ns_inner - // comments at the end! // even more comments at the end! diff --git a/wrap/tests/testWrap.cpp b/wrap/tests/testWrap.cpp index de1935f50..e49fb88d9 100644 --- a/wrap/tests/testWrap.cpp +++ b/wrap/tests/testWrap.cpp @@ -15,6 +15,7 @@ * @author Frank Dellaert **/ +#include #include #include #include @@ -56,12 +57,11 @@ TEST( wrap, check_exception ) { /* ************************************************************************* */ TEST( wrap, parse ) { - string path = topdir + "/wrap/tests"; + string header_path = topdir + "/wrap/tests"; - Module module(path.c_str(), "geometry",enable_verbose); + Module module(header_path.c_str(), "geometry",enable_verbose); EXPECT_LONGS_EQUAL(3, module.classes.size()); - //Hack to solve issues with instantiating Modules - path = topdir + "/wrap"; + string path = topdir + "/wrap"; // check first class, Point2 { @@ -102,26 +102,32 @@ TEST( wrap, parse ) { EXPECT(m1.is_const_); } - // // Test class is the third one - // LONGS_EQUAL(3, module.classes.size()); - // Class testCls = module.classes.at(2); - // EXPECT_LONGS_EQUAL( 2, testCls.constructors.size()); - // EXPECT_LONGS_EQUAL(19, testCls.methods.size()); - // EXPECT_LONGS_EQUAL( 0, testCls.static_methods.size()); - // - // // function to parse: pair return_pair (Vector v, Matrix A) const; - // Method m2 = testCls.methods.front(); - // EXPECT(m2.returnVal_.isPair); - // EXPECT(m2.returnVal_.category1 == ReturnValue::EIGEN); - // EXPECT(m2.returnVal_.category2 == ReturnValue::EIGEN); + // Test class is the third one + { + LONGS_EQUAL(3, module.classes.size()); + Class testCls = module.classes.at(2); + EXPECT_LONGS_EQUAL( 2, testCls.constructors.size()); + EXPECT_LONGS_EQUAL(19, testCls.methods.size()); + EXPECT_LONGS_EQUAL( 0, testCls.static_methods.size()); + + // function to parse: pair return_pair (Vector v, Matrix A) const; + Method m2 = testCls.methods.front(); + EXPECT(m2.returnVal_.isPair); + EXPECT(m2.returnVal_.category1 == ReturnValue::EIGEN); + EXPECT(m2.returnVal_.category2 == ReturnValue::EIGEN); + } } /* ************************************************************************* */ TEST( wrap, matlab_code ) { // Parse into class object - string path = topdir + "/wrap/tests"; - Module module(path,"geometry",enable_verbose); - path = topdir + "/wrap"; + string header_path = topdir + "/wrap/tests"; + Module module(header_path,"geometry",enable_verbose); + string path = topdir + "/wrap"; + + // clean out previous generated code + string cleanCmd = "rm -rf actual"; + system(cleanCmd.c_str()); // emit MATLAB code // make_geometry will not compile, use make testwrap to generate real make