Commented out grammar

release/4.3a0
dellaert 2014-11-30 20:46:19 +01:00
parent 24f5636d6a
commit 5bcd5d3c89
1 changed files with 91 additions and 95 deletions

View File

@ -23,13 +23,13 @@
using namespace std; using namespace std;
using namespace wrap; using namespace wrap;
/* ************************************************************************* */ //******************************************************************************
// Constructor // Constructor
TEST( Method, Constructor ) { TEST( Method, Constructor ) {
Method method; Method method;
} }
/* ************************************************************************* */ //******************************************************************************
// addOverload // addOverload
TEST( Method, addOverload ) { TEST( Method, addOverload ) {
Method method; Method method;
@ -42,105 +42,101 @@ TEST( Method, addOverload ) {
EXPECT_LONGS_EQUAL(2, method.nrOverloads()); EXPECT_LONGS_EQUAL(2, method.nrOverloads());
} }
// http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html //// http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html
struct method_grammar: public classic::grammar<method_grammar> { //struct method_grammar: public classic::grammar<method_grammar> {
wrap::Method& result_; ///< successful parse will be placed in here
ArgumentList args;
Argument arg0, arg;
TypeGrammar argument_type_g;
ReturnType retType0, retType;
TypeGrammar returntype_g;
ReturnValue retVal0, retVal;
/// Construct type grammar and specify where result is placed
method_grammar(wrap::Method& result) :
result_(result), argument_type_g(arg.type), returntype_g(retType) {
}
/// Definition of type grammar
template<typename ScannerT>
struct definition: basic_rules<ScannerT> {
typedef classic::rule<ScannerT> Rule;
Rule templateArgValue_p, templateArgValues_p, argument_p, argumentList_p,
returnType1_p, returnType2_p, pair_p, returnValue_p, methodName_p,
method_p;
definition(method_grammar const& self) {
using namespace wrap;
using namespace classic;
// Rule templateArgValue_p = type_grammar(self.templateArgValue);
// //
// // template<CALIBRATION = {gtsam::Cal3DS2}> // wrap::Method& result_; ///< successful parse will be placed in here
// Rule templateArgValues_p = (str_p("template") >> '<' >> name_p >> '='
// >> '{' >> !(templateArgValue_p >> *(',' >> templateArgValue_p)) >> '}'
// >> '>');
// //
// NOTE: allows for pointers to all types // ArgumentList args;
// Slightly more permissive than before on basis/eigen type qualification // Argument arg0, arg;
argument_p = // // TypeGrammar argument_type_g;
!str_p("const")[assign_a(self.arg.is_const, true)] //
>> self.argument_type_g //
>> (!ch_p('&')[assign_a(self.arg.is_ref, true)]
| !ch_p('*')[assign_a(self.arg.is_ptr, true)]) //
[push_back_a(self.args, self.arg)] //
[assign_a(self.arg, self.arg0)];
argumentList_p = !argument_p >> *(',' >> argument_p);
// //
returnType1_p = self.returntype_g // // ReturnType retType0, retType;
[assign_a(self.retVal.type1, retType)] // // TypeGrammar returntype_g;
[assign_a(self.retType, self.retType0)]; //
// ReturnValue retVal0, retVal;
returnType2_p = self.returntype_g // //
[assign_a(self.retVal.type2, retType)] // // /// Construct type grammar and specify where result is placed
[assign_a(self.retType, self.retType0)]; // method_grammar(wrap::Method& result) :
// result_(result), argument_type_g(arg.type), returntype_g(retType) {
pair_p = (str_p("pair") >> '<' >> returnType1_p >> ',' >> returnType2_p // }
>> '>')[assign_a(self.retVal.isPair, true)]; //
// /// Definition of type grammar
returnValue_p = pair_p | returnType1_p; // template<typename ScannerT>
// struct definition: basic_rules<ScannerT> {
methodName_p = lexeme_d[(upper_p | lower_p) >> *(alnum_p | '_')]; //
// typedef classic::rule<ScannerT> Rule;
// gtsam::Values retract(const gtsam::VectorValues& delta) const; //
method_p = // Rule templateArgValue_p, templateArgValues_p, argument_p, argumentList_p,
// !templateArgValues_p >> // returnType1_p, returnType2_p, pair_p, returnValue_p, methodName_p,
(returnValue_p >> methodName_p >> '(' >> argumentList_p >> ')' // method_p;
>> !str_p("const") >> ';' >> *basic_rules<ScannerT>::comments_p); //
} // definition(method_grammar const& self) {
//
Rule const& start() const { // using namespace wrap;
return method_p; // using namespace classic;
} //
//// Rule templateArgValue_p = type_grammar(self.templateArgValue);
}; ////
}; //// // template<CALIBRATION = {gtsam::Cal3DS2}>
// method_grammar //// Rule templateArgValues_p = (str_p("template") >> '<' >> name_p >> '='
//// >> '{' >> !(templateArgValue_p >> *(',' >> templateArgValue_p)) >> '}'
//// >> '>');
////
// // Create type grammar that will place result in actual
// ArgumentList actual;
// ArgumentListGrammar g(actual);
//
// EXPECT(parse("(const gtsam::Point2& p4)", g, space_p).full);
// EXPECT_LONGS_EQUAL(1, actual.size());
// actual.clear();
//
// returnType1_p = self.returntype_g //
// [assign_a(self.retVal.type1, retType)] //
// [assign_a(self.retType, self.retType0)];
//
// returnType2_p = self.returntype_g //
// [assign_a(self.retVal.type2, retType)] //
// [assign_a(self.retType, self.retType0)];
//
// pair_p = (str_p("pair") >> '<' >> returnType1_p >> ',' >> returnType2_p
// >> '>')[assign_a(self.retVal.isPair, true)];
//
// returnValue_p = pair_p | returnType1_p;
//
// methodName_p = lexeme_d[(upper_p | lower_p) >> *(alnum_p | '_')];
//
// // gtsam::Values retract(const gtsam::VectorValues& delta) const;
// method_p =
//// !templateArgValues_p >>
// (returnValue_p >> methodName_p >> '(' >> argumentList_p >> ')'
// >> !str_p("const") >> ';' >> *basic_rules<ScannerT>::comments_p);
// }
//
// Rule const& start() const {
// return method_p;
// }
//
// };
//};
//// method_grammar
//
////******************************************************************************
//TEST( Method, grammar ) {
//
// using classic::space_p;
//
// // Create type grammar that will place result in actual
// Method actual;
// method_grammar method_g(actual);
//
// // a class type with namespaces
// EXPECT(parse("double x() const;", method_g, space_p).full);
//}
//****************************************************************************** //******************************************************************************
TEST( Method, grammar ) {
using classic::space_p;
// Create type grammar that will place result in actual
Method actual;
method_grammar method_g(actual);
// a class type with namespaces
EXPECT(parse("double x() const;", method_g, space_p).full);
}
/* ************************************************************************* */
int main() { int main() {
TestResult tr; TestResult tr;
return TestRegistry::runAllTests(tr); return TestRegistry::runAllTests(tr);
} }
/* ************************************************************************* */ //******************************************************************************