GlobalFunctionGrammar done and used
parent
a8de6c4dc3
commit
41d2783beb
|
@ -66,10 +66,12 @@ typedef std::map<std::string, GlobalFunction> GlobalFunctions;
|
||||||
struct GlobalFunctionGrammar: public classic::grammar<GlobalFunctionGrammar> {
|
struct GlobalFunctionGrammar: public classic::grammar<GlobalFunctionGrammar> {
|
||||||
|
|
||||||
GlobalFunctions& global_functions_; ///< successful parse will be placed in here
|
GlobalFunctions& global_functions_; ///< successful parse will be placed in here
|
||||||
|
std::vector<std::string>& namespaces_;
|
||||||
|
|
||||||
/// Construct type grammar and specify where result is placed
|
/// Construct type grammar and specify where result is placed
|
||||||
GlobalFunctionGrammar(GlobalFunctions& global_functions) :
|
GlobalFunctionGrammar(GlobalFunctions& global_functions,
|
||||||
global_functions_(global_functions) {
|
std::vector<std::string>& namespaces) :
|
||||||
|
global_functions_(global_functions), namespaces_(namespaces) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Definition of type grammar
|
/// Definition of type grammar
|
||||||
|
@ -102,7 +104,8 @@ struct GlobalFunctionGrammar: public classic::grammar<GlobalFunctionGrammar> {
|
||||||
global_function_p = (returnValue_g
|
global_function_p = (returnValue_g
|
||||||
>> globalFunctionName_p[assign_a(globalFunction.name_)]
|
>> globalFunctionName_p[assign_a(globalFunction.name_)]
|
||||||
>> argumentList_g >> ';' >> *comments_p) //
|
>> argumentList_g >> ';' >> *comments_p) //
|
||||||
[bl::bind(&GlobalFunction::addOverload,
|
[assign_a(globalFunction.namespaces_, self.namespaces_)][bl::bind(
|
||||||
|
&GlobalFunction::addOverload,
|
||||||
bl::var(self.global_functions_)[bl::var(globalFunction.name_)],
|
bl::var(self.global_functions_)[bl::var(globalFunction.name_)],
|
||||||
bl::var(globalFunction), bl::var(args), bl::var(retVal),
|
bl::var(globalFunction), bl::var(args), bl::var(retVal),
|
||||||
boost::none, verbose)] //
|
boost::none, verbose)] //
|
||||||
|
@ -118,5 +121,5 @@ struct GlobalFunctionGrammar: public classic::grammar<GlobalFunctionGrammar> {
|
||||||
};
|
};
|
||||||
// GlobalFunctionGrammar
|
// GlobalFunctionGrammar
|
||||||
|
|
||||||
} // \namespace wrap
|
}// \namespace wrap
|
||||||
|
|
||||||
|
|
|
@ -126,30 +126,8 @@ void Module::parseMarkup(const std::string& data) {
|
||||||
[push_back_a(templateInstantiationTypedefs, singleInstantiation)]
|
[push_back_a(templateInstantiationTypedefs, singleInstantiation)]
|
||||||
[assign_a(singleInstantiation, singleInstantiation0)];
|
[assign_a(singleInstantiation, singleInstantiation0)];
|
||||||
|
|
||||||
// NOTE: allows for pointers to all types
|
// Create grammar for global functions
|
||||||
ArgumentList args;
|
GlobalFunctionGrammar global_function_g(global_functions,namespaces);
|
||||||
ArgumentListGrammar argumentList_g(args);
|
|
||||||
|
|
||||||
vector<string> namespaces_return; /// namespace for current return type
|
|
||||||
Rule namespace_ret_p = basic.namespace_p[push_back_a(namespaces_return)] >> str_p("::");
|
|
||||||
|
|
||||||
ReturnValue retVal0, retVal;
|
|
||||||
ReturnValueGrammar returnValue_g(retVal);
|
|
||||||
|
|
||||||
Rule globalFunctionName_p = lexeme_d[(upper_p | lower_p) >> *(alnum_p | '_')];
|
|
||||||
|
|
||||||
// parse a global function
|
|
||||||
Qualified globalFunction;
|
|
||||||
Rule global_function_p =
|
|
||||||
(returnValue_g >> globalFunctionName_p[assign_a(globalFunction.name_)] >>
|
|
||||||
argumentList_g >> ';' >> *basic.comments_p)
|
|
||||||
[assign_a(globalFunction.namespaces_,namespaces)]
|
|
||||||
[bl::bind(&GlobalFunction::addOverload,
|
|
||||||
bl::var(global_functions)[bl::var(globalFunction.name_)],
|
|
||||||
bl::var(globalFunction), bl::var(args), bl::var(retVal), boost::none,verbose)]
|
|
||||||
[assign_a(retVal,retVal0)]
|
|
||||||
[clear_a(globalFunction)]
|
|
||||||
[clear_a(args)];
|
|
||||||
|
|
||||||
Rule include_p = str_p("#include") >> ch_p('<') >> (*(anychar_p - '>'))[push_back_a(includes)] >> ch_p('>');
|
Rule include_p = str_p("#include") >> ch_p('<') >> (*(anychar_p - '>'))[push_back_a(includes)] >> ch_p('>');
|
||||||
|
|
||||||
|
@ -162,7 +140,7 @@ void Module::parseMarkup(const std::string& data) {
|
||||||
(str_p("namespace")
|
(str_p("namespace")
|
||||||
>> basic.namespace_p[push_back_a(namespaces)]
|
>> basic.namespace_p[push_back_a(namespaces)]
|
||||||
>> ch_p('{')
|
>> ch_p('{')
|
||||||
>> *(include_p | class_p | templateSingleInstantiation_p | global_function_p | namespace_def_p | basic.comments_p)
|
>> *(include_p | class_p | templateSingleInstantiation_p | global_function_g | namespace_def_p | basic.comments_p)
|
||||||
>> ch_p('}'))
|
>> ch_p('}'))
|
||||||
[pop_a(namespaces)];
|
[pop_a(namespaces)];
|
||||||
|
|
||||||
|
@ -182,7 +160,7 @@ void Module::parseMarkup(const std::string& data) {
|
||||||
|
|
||||||
Rule module_content_p = basic.comments_p | include_p | class_p
|
Rule module_content_p = basic.comments_p | include_p | class_p
|
||||||
| templateSingleInstantiation_p | forward_declaration_p
|
| templateSingleInstantiation_p | forward_declaration_p
|
||||||
| global_function_p | namespace_def_p;
|
| global_function_g | namespace_def_p;
|
||||||
|
|
||||||
Rule module_p = *module_content_p >> !end_p;
|
Rule module_p = *module_content_p >> !end_p;
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,8 @@ TEST( GlobalFunction, Grammar ) {
|
||||||
|
|
||||||
// Create type grammar that will place result in actual
|
// Create type grammar that will place result in actual
|
||||||
GlobalFunctions actual;
|
GlobalFunctions actual;
|
||||||
GlobalFunctionGrammar g(actual);
|
vector<string> namespaces;
|
||||||
|
GlobalFunctionGrammar g(actual,namespaces);
|
||||||
|
|
||||||
// a class type with namespaces
|
// a class type with namespaces
|
||||||
EXPECT(parse("Vector aGlobalFunction();", g, space_p).full);
|
EXPECT(parse("Vector aGlobalFunction();", g, space_p).full);
|
||||||
|
|
Loading…
Reference in New Issue