Parsing for namespaces now works in all tests
parent
90e9426d9c
commit
aa2eccbcb4
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include "Module.h"
|
#include "Module.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
#include "pop_actor.h"
|
||||||
|
|
||||||
//#define BOOST_SPIRIT_DEBUG
|
//#define BOOST_SPIRIT_DEBUG
|
||||||
#include <boost/spirit/include/classic_core.hpp>
|
#include <boost/spirit/include/classic_core.hpp>
|
||||||
|
@ -51,7 +52,7 @@ Module::Module(const string& interfacePath,
|
||||||
Method method0(enable_verbose), method(enable_verbose);
|
Method method0(enable_verbose), method(enable_verbose);
|
||||||
StaticMethod static_method0(enable_verbose), static_method(enable_verbose);
|
StaticMethod static_method0(enable_verbose), static_method(enable_verbose);
|
||||||
Class cls0(enable_verbose),cls(enable_verbose);
|
Class cls0(enable_verbose),cls(enable_verbose);
|
||||||
vector<string> namespaces, namespaces_parent;
|
vector<string> namespaces, namespaces_parent, namespaces_temp;
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
// Grammar with actions that build the Class object. Actions are
|
// Grammar with actions that build the Class object. Actions are
|
||||||
|
@ -161,11 +162,11 @@ Module::Module(const string& interfacePath,
|
||||||
Rule namespace_name_p = lexeme_d[(upper_p | lower_p) >> *(alnum_p | '_')];
|
Rule namespace_name_p = lexeme_d[(upper_p | lower_p) >> *(alnum_p | '_')];
|
||||||
|
|
||||||
Rule namespace_p = str_p("namespace") >>
|
Rule namespace_p = str_p("namespace") >>
|
||||||
namespace_name_p[assign_a(namespaces_parent, namespaces)][push_back_a(namespaces)] // save previous state
|
namespace_name_p[push_back_a(namespaces)]
|
||||||
>> ch_p('{') >>
|
>> ch_p('{') >>
|
||||||
*(class_p | namespace_p | comments_p) >>
|
*(class_p | namespace_p | comments_p) >>
|
||||||
str_p("}///\\namespace") // end namespace, avoid confusion with classes
|
str_p("}///\\namespace") // end namespace, avoid confusion with classes
|
||||||
[assign_a(namespaces, namespaces_parent)]; // switch back to parent namespace
|
[pop_a(namespaces)];
|
||||||
|
|
||||||
Rule module_content_p = comments_p | class_p | namespace_p ;
|
Rule module_content_p = comments_p | class_p | namespace_p ;
|
||||||
|
|
||||||
|
@ -204,16 +205,6 @@ Module::Module(const string& interfacePath,
|
||||||
printf("parsing stopped at \n%.20s\n",info.stop);
|
printf("parsing stopped at \n%.20s\n",info.stop);
|
||||||
throw ParseFailed(info.length);
|
throw ParseFailed(info.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (!namespaces.empty()) {
|
|
||||||
// cout << "Namespaces not closed, remaining: ";
|
|
||||||
// BOOST_FOREACH(const string& ns, namespaces)
|
|
||||||
// cout << ns << " ";
|
|
||||||
// cout << endl;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (!cls.name.empty())
|
|
||||||
// cout << "\nClass name: " << cls.name << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
/**
|
||||||
|
* @file pop_actor.h
|
||||||
|
*
|
||||||
|
* @brief An actor to pop a vector/container, based off of the clear_actor
|
||||||
|
*
|
||||||
|
* @date Dec 8, 2011
|
||||||
|
* @author Alex Cunningham
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <boost/spirit/include/classic_ref_actor.hpp>
|
||||||
|
|
||||||
|
namespace boost { namespace spirit {
|
||||||
|
|
||||||
|
BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// Summary:
|
||||||
|
// A semantic action policy that calls pop_back method.
|
||||||
|
// (This doc uses convention available in actors.hpp)
|
||||||
|
//
|
||||||
|
// Actions (what it does):
|
||||||
|
// ref.pop_back();
|
||||||
|
//
|
||||||
|
// Policy name:
|
||||||
|
// clear_action
|
||||||
|
//
|
||||||
|
// Policy holder, corresponding helper method:
|
||||||
|
// ref_actor, clear_a( ref );
|
||||||
|
//
|
||||||
|
// () operators: both.
|
||||||
|
//
|
||||||
|
// See also ref_actor for more details.
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
struct pop_action
|
||||||
|
{
|
||||||
|
template<
|
||||||
|
typename T
|
||||||
|
>
|
||||||
|
void act(T& ref_) const
|
||||||
|
{
|
||||||
|
ref_.pop_back();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// helper method that creates a and_assign_actor.
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
template<typename T>
|
||||||
|
inline ref_actor<T,pop_action> pop_a(T& ref_)
|
||||||
|
{
|
||||||
|
return ref_actor<T,pop_action>(ref_);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_SPIRIT_CLASSIC_NAMESPACE_END
|
||||||
|
|
||||||
|
}}
|
||||||
|
|
|
@ -26,6 +26,12 @@ class ClassB {
|
||||||
|
|
||||||
}///\namespace
|
}///\namespace
|
||||||
|
|
||||||
|
class ClassC {
|
||||||
|
};
|
||||||
|
|
||||||
}///\namespace
|
}///\namespace
|
||||||
|
|
||||||
|
class ClassD {
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,7 @@ TEST( wrap, parse ) {
|
||||||
TEST( wrap, parse_namespaces ) {
|
TEST( wrap, parse_namespaces ) {
|
||||||
string header_path = topdir + "/wrap/tests";
|
string header_path = topdir + "/wrap/tests";
|
||||||
Module module(header_path.c_str(), "testNamespaces",enable_verbose);
|
Module module(header_path.c_str(), "testNamespaces",enable_verbose);
|
||||||
EXPECT_LONGS_EQUAL(4, module.classes.size());
|
EXPECT_LONGS_EQUAL(6, module.classes.size());
|
||||||
|
|
||||||
Class cls1 = module.classes.at(0);
|
Class cls1 = module.classes.at(0);
|
||||||
EXPECT(assert_equal("ClassA", cls1.name));
|
EXPECT(assert_equal("ClassA", cls1.name));
|
||||||
|
@ -145,6 +145,17 @@ TEST( wrap, parse_namespaces ) {
|
||||||
EXPECT_LONGS_EQUAL(2, cls4.namespaces.size());
|
EXPECT_LONGS_EQUAL(2, cls4.namespaces.size());
|
||||||
EXPECT(assert_equal("ns2", cls4.namespaces.front()));
|
EXPECT(assert_equal("ns2", cls4.namespaces.front()));
|
||||||
EXPECT(assert_equal("ns3", cls4.namespaces.back()));
|
EXPECT(assert_equal("ns3", cls4.namespaces.back()));
|
||||||
|
|
||||||
|
Class cls5 = module.classes.at(4);
|
||||||
|
EXPECT(assert_equal("ClassC", cls5.name));
|
||||||
|
EXPECT_LONGS_EQUAL(1, cls5.namespaces.size());
|
||||||
|
EXPECT(assert_equal("ns2", cls5.namespaces.front()));
|
||||||
|
|
||||||
|
Class cls6 = module.classes.at(5);
|
||||||
|
EXPECT(assert_equal("ClassD", cls6.name));
|
||||||
|
EXPECT_LONGS_EQUAL(0, cls6.namespaces.size());
|
||||||
|
if (!cls6.namespaces.empty())
|
||||||
|
cout << "Extraneous namespace: " << cls6.namespaces.front() << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
Loading…
Reference in New Issue