Successfully used TypeListGrammar

release/4.3a0
dellaert 2014-12-01 12:14:08 +01:00
parent 4d1225cda7
commit 9a77072654
3 changed files with 9 additions and 18 deletions

View File

@ -114,35 +114,25 @@ void Module::parseMarkup(const std::string& data) {
// TODO, do we really need cls here? Non-local // TODO, do we really need cls here? Non-local
Class cls0(verbose),cls(verbose); Class cls0(verbose),cls(verbose);
// parse "gtsam::Pose2" and add to templateArgValues
Qualified templateArgValue;
vector<Qualified> templateArgValues;
TypeGrammar templateArgValue_g(templateArgValue);
Rule templateArgValue_p = templateArgValue_g
[push_back_a(templateArgValues, templateArgValue)]
[clear_a(templateArgValue)];
// template<CALIBRATION = {gtsam::Cal3DS2}> // template<CALIBRATION = {gtsam::Cal3DS2}>
string templateArgName; string templateArgName;
vector<Qualified> templateArgValues;
TypeListGrammar<'{','}'> templateArgValues_g(templateArgValues);
Rule templateArgValues_p = Rule templateArgValues_p =
(str_p("template") >> (str_p("template") >>
'<' >> basic.name_p[assign_a(templateArgName)] >> '=' >> '<' >> basic.name_p[assign_a(templateArgName)] >> '=' >>
'{' >> !(templateArgValue_p >> *(',' >> templateArgValue_p)) >> '}' >> templateArgValues_g >> '>');
'>');
// parse "gtsam::Pose2" and add to singleInstantiation.typeList // parse "gtsam::Pose2" and add to singleInstantiation.typeList
TemplateInstantiationTypedef singleInstantiation, singleInstantiation0; TemplateInstantiationTypedef singleInstantiation, singleInstantiation0;
Rule templateSingleInstantiationArg_p = templateArgValue_g TypeListGrammar<'<','>'> typelist_g(singleInstantiation.typeList);
[push_back_a(singleInstantiation.typeList, templateArgValue)]
[clear_a(templateArgValue)];
// typedef gtsam::RangeFactor<gtsam::Pose2, gtsam::Point2> RangeFactorPosePoint2; // typedef gtsam::RangeFactor<gtsam::Pose2, gtsam::Point2> RangeFactorPosePoint2;
vector<string> namespaces; // current namespace tag vector<string> namespaces; // current namespace tag
TypeGrammar instantiationClass_g(singleInstantiation.class_); TypeGrammar instantiationClass_g(singleInstantiation.class_);
Rule templateSingleInstantiation_p = Rule templateSingleInstantiation_p =
(str_p("typedef") >> instantiationClass_g >> (str_p("typedef") >> instantiationClass_g >>
'<' >> templateSingleInstantiationArg_p >> *(',' >> templateSingleInstantiationArg_p) >> typelist_g >>
'>' >>
basic.className_p[assign_a(singleInstantiation.name_)] >> basic.className_p[assign_a(singleInstantiation.name_)] >>
';') ';')
[assign_a(singleInstantiation.namespaces_, namespaces)] [assign_a(singleInstantiation.namespaces_, namespaces)]

View File

@ -218,7 +218,8 @@ public:
/* ************************************************************************* */ /* ************************************************************************* */
// 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 TypeListGrammar: public classic::grammar<TypeListGrammar> { template <char OPEN, char CLOSE>
struct TypeListGrammar: public classic::grammar<TypeListGrammar<OPEN,CLOSE> > {
typedef std::vector<wrap::Qualified> TypeList; typedef std::vector<wrap::Qualified> TypeList;
TypeList& result_; ///< successful parse will be placed in here TypeList& result_; ///< successful parse will be placed in here
@ -244,7 +245,7 @@ struct TypeListGrammar: public classic::grammar<TypeListGrammar> {
type_p = self.type_g // type_p = self.type_g //
[push_back_a(self.result_, self.type)] // [push_back_a(self.result_, self.type)] //
[clear_a(self.type)]; [clear_a(self.type)];
typeList_p = '{' >> !type_p >> *(',' >> type_p) >> '}'; typeList_p = OPEN >> !type_p >> *(',' >> type_p) >> CLOSE;
} }
Rule const& start() const { Rule const& start() const {

View File

@ -90,7 +90,7 @@ TEST( TypeList, grammar ) {
// Create type grammar that will place result in actual // Create type grammar that will place result in actual
vector<Qualified> actual; vector<Qualified> actual;
TypeListGrammar g(actual); TypeListGrammar<'{','}'> g(actual);
EXPECT(parse("{gtsam::Point2}", g, space_p).full); EXPECT(parse("{gtsam::Point2}", g, space_p).full);
EXPECT_LONGS_EQUAL(1, actual.size()); EXPECT_LONGS_EQUAL(1, actual.size());