diff --git a/wrap/Module.cpp b/wrap/Module.cpp index b31ea2b12..a94fb59b9 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -114,35 +114,25 @@ void Module::parseMarkup(const std::string& data) { // TODO, do we really need cls here? Non-local Class cls0(verbose),cls(verbose); - // parse "gtsam::Pose2" and add to templateArgValues - Qualified templateArgValue; - vector templateArgValues; - TypeGrammar templateArgValue_g(templateArgValue); - Rule templateArgValue_p = templateArgValue_g - [push_back_a(templateArgValues, templateArgValue)] - [clear_a(templateArgValue)]; - // template string templateArgName; + vector templateArgValues; + TypeListGrammar<'{','}'> templateArgValues_g(templateArgValues); Rule templateArgValues_p = (str_p("template") >> '<' >> basic.name_p[assign_a(templateArgName)] >> '=' >> - '{' >> !(templateArgValue_p >> *(',' >> templateArgValue_p)) >> '}' >> - '>'); + templateArgValues_g >> '>'); // parse "gtsam::Pose2" and add to singleInstantiation.typeList TemplateInstantiationTypedef singleInstantiation, singleInstantiation0; - Rule templateSingleInstantiationArg_p = templateArgValue_g - [push_back_a(singleInstantiation.typeList, templateArgValue)] - [clear_a(templateArgValue)]; + TypeListGrammar<'<','>'> typelist_g(singleInstantiation.typeList); // typedef gtsam::RangeFactor RangeFactorPosePoint2; vector namespaces; // current namespace tag TypeGrammar instantiationClass_g(singleInstantiation.class_); Rule templateSingleInstantiation_p = (str_p("typedef") >> instantiationClass_g >> - '<' >> templateSingleInstantiationArg_p >> *(',' >> templateSingleInstantiationArg_p) >> - '>' >> + typelist_g >> basic.className_p[assign_a(singleInstantiation.name_)] >> ';') [assign_a(singleInstantiation.namespaces_, namespaces)] diff --git a/wrap/Qualified.h b/wrap/Qualified.h index 0466b10f3..29b961518 100644 --- a/wrap/Qualified.h +++ b/wrap/Qualified.h @@ -218,7 +218,8 @@ public: /* ************************************************************************* */ // http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html -struct TypeListGrammar: public classic::grammar { +template +struct TypeListGrammar: public classic::grammar > { typedef std::vector TypeList; TypeList& result_; ///< successful parse will be placed in here @@ -244,7 +245,7 @@ struct TypeListGrammar: public classic::grammar { type_p = self.type_g // [push_back_a(self.result_, self.type)] // [clear_a(self.type)]; - typeList_p = '{' >> !type_p >> *(',' >> type_p) >> '}'; + typeList_p = OPEN >> !type_p >> *(',' >> type_p) >> CLOSE; } Rule const& start() const { diff --git a/wrap/tests/testType.cpp b/wrap/tests/testType.cpp index 1b55a1bb3..f06a88962 100644 --- a/wrap/tests/testType.cpp +++ b/wrap/tests/testType.cpp @@ -90,7 +90,7 @@ TEST( TypeList, grammar ) { // Create type grammar that will place result in actual vector actual; - TypeListGrammar g(actual); + TypeListGrammar<'{','}'> g(actual); EXPECT(parse("{gtsam::Point2}", g, space_p).full); EXPECT_LONGS_EQUAL(1, actual.size());