From 24f5636d6a853d4a54dc6db083bd7ccc80e9c14f Mon Sep 17 00:00:00 2001 From: dellaert Date: Sun, 30 Nov 2014 20:25:26 +0100 Subject: [PATCH] Moved to header --- wrap/Argument.h | 94 ++++++++++++++++++++++++++++++++++++- wrap/tests/testArgument.cpp | 90 ----------------------------------- 2 files changed, 93 insertions(+), 91 deletions(-) diff --git a/wrap/Argument.h b/wrap/Argument.h index 2a3e4b18b..c49075932 100644 --- a/wrap/Argument.h +++ b/wrap/Argument.h @@ -124,5 +124,97 @@ struct ArgumentList: public std::vector { }; -} // \namespace wrap +static const bool T = true; + +/* ************************************************************************* */ +// http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html +struct ArgumentGrammar: public classic::grammar { + + wrap::Argument& result_; ///< successful parse will be placed in here + TypeGrammar argument_type_g; + + /// Construct type grammar and specify where result is placed + ArgumentGrammar(wrap::Argument& result) : + result_(result), argument_type_g(result.type) { + } + + /// Definition of type grammar + template + struct definition: basic_rules { + + typedef classic::rule Rule; + + Rule argument_p, argumentList_p; + + definition(ArgumentGrammar const& self) { + + using namespace wrap; + using namespace classic; + + // NOTE: allows for pointers to all types + // Slightly more permissive than before on basis/eigen type qualification + // Also, currently parses Point2*&, can't make it work otherwise :-( + argument_p = !str_p("const")[assign_a(self.result_.is_const, T)] // + >> self.argument_type_g // + >> !ch_p('*')[assign_a(self.result_.is_ptr, T)] + >> !ch_p('&')[assign_a(self.result_.is_ref, T)] + >> basic_rules::name_p[assign_a(self.result_.name)]; + } + + Rule const& start() const { + return argument_p; + } + + }; +}; +// ArgumentGrammar + +/* ************************************************************************* */ +// http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html +struct ArgumentListGrammar: public classic::grammar { + + wrap::ArgumentList& result_; ///< successful parse will be placed in here + + Argument arg0, arg; + ArgumentGrammar argument_g; + + /// Construct type grammar and specify where result is placed + ArgumentListGrammar(wrap::ArgumentList& result) : + result_(result), argument_g(arg) { + } + + /// Definition of type grammar + template + struct definition: basic_rules { + + typedef classic::rule Rule; + + Rule argument_p, argumentList_p; + + definition(ArgumentListGrammar const& self) { + + using namespace wrap; + using namespace classic; + + // NOTE: allows for pointers to all types + // Slightly more permissive than before on basis/eigen type qualification + argument_p = self.argument_g // + [push_back_a(self.result_, self.arg)] // +// [assign_a(self.arg, self.arg0)] + ; + + argumentList_p = '(' >> !argument_p >> *(',' >> argument_p) >> ')'; + } + + Rule const& start() const { + return argumentList_p; + } + + }; +}; +// ArgumentListGrammar + +/* ************************************************************************* */ + +}// \namespace wrap diff --git a/wrap/tests/testArgument.cpp b/wrap/tests/testArgument.cpp index 8a50d694f..31269c652 100644 --- a/wrap/tests/testArgument.cpp +++ b/wrap/tests/testArgument.cpp @@ -23,51 +23,6 @@ using namespace std; using namespace wrap; -static const bool T = true; - -/* ************************************************************************* */ -// http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html -struct ArgumentGrammar: public classic::grammar { - - wrap::Argument& result_; ///< successful parse will be placed in here - TypeGrammar argument_type_g; - - /// Construct type grammar and specify where result is placed - ArgumentGrammar(wrap::Argument& result) : - result_(result), argument_type_g(result.type) { - } - - /// Definition of type grammar - template - struct definition: basic_rules { - - typedef classic::rule Rule; - - Rule argument_p, argumentList_p; - - definition(ArgumentGrammar const& self) { - - using namespace wrap; - using namespace classic; - - // NOTE: allows for pointers to all types - // Slightly more permissive than before on basis/eigen type qualification - // Also, currently parses Point2*&, can't make it work otherwise :-( - argument_p = !str_p("const")[assign_a(self.result_.is_const, T)] // - >> self.argument_type_g // - >> !ch_p('*')[assign_a(self.result_.is_ptr, T)] - >> !ch_p('&')[assign_a(self.result_.is_ref, T)] - >> basic_rules::name_p[assign_a(self.result_.name)]; - } - - Rule const& start() const { - return argument_p; - } - - }; -}; -// ArgumentGrammar - //****************************************************************************** TEST( Argument, grammar ) { @@ -122,51 +77,6 @@ TEST( Argument, grammar ) { actual = arg0; } -/* ************************************************************************* */ -// http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html -struct ArgumentListGrammar: public classic::grammar { - - wrap::ArgumentList& result_; ///< successful parse will be placed in here - - Argument arg0, arg; - ArgumentGrammar argument_g; - - /// Construct type grammar and specify where result is placed - ArgumentListGrammar(wrap::ArgumentList& result) : - result_(result), argument_g(arg) { - } - - /// Definition of type grammar - template - struct definition: basic_rules { - - typedef classic::rule Rule; - - Rule argument_p, argumentList_p; - - definition(ArgumentListGrammar const& self) { - - using namespace wrap; - using namespace classic; - - // NOTE: allows for pointers to all types - // Slightly more permissive than before on basis/eigen type qualification - argument_p = self.argument_g // - [push_back_a(self.result_, self.arg)] // -// [assign_a(self.arg, self.arg0)] - ; - - argumentList_p = '(' >> !argument_p >> *(',' >> argument_p) >> ')'; - } - - Rule const& start() const { - return argumentList_p; - } - - }; -}; -// ArgumentListGrammar - //****************************************************************************** TEST( ArgumentList, grammar ) {