From 19ea0436dbf82d7c0d72e347a84b2b6915c8f85a Mon Sep 17 00:00:00 2001 From: dellaert Date: Mon, 1 Dec 2014 11:35:48 +0100 Subject: [PATCH] Moved to header --- wrap/Qualified.h | 43 +++++++++++++++++++++++++++++++++++++++++ wrap/tests/testType.cpp | 39 ------------------------------------- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/wrap/Qualified.h b/wrap/Qualified.h index 494d6b0ff..6a5a3e9ce 100644 --- a/wrap/Qualified.h +++ b/wrap/Qualified.h @@ -161,6 +161,8 @@ public: }; +/* ************************************************************************* */ +/// Som basic rules used by all parsers template struct basic_rules { @@ -194,6 +196,7 @@ struct basic_rules { } }; +/* ************************************************************************* */ // http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html class TypeGrammar: public classic::grammar { @@ -255,6 +258,46 @@ public: }; // type_grammar +/* ************************************************************************* */ +// http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html +struct TypeListGrammar: public classic::grammar { + + typedef std::vector TypeList; + TypeList& result_; ///< successful parse will be placed in here + + mutable wrap::Qualified type; // temporary type for use during parsing + TypeGrammar type_g; + + /// Construct type grammar and specify where result is placed + TypeListGrammar(TypeList& result) : + result_(result), type_g(type) { + } + + /// Definition of type grammar + template + struct definition: basic_rules { + + typedef classic::rule Rule; + + Rule type_p, typeList_p; + + definition(TypeListGrammar const& self) { + using namespace classic; + type_p = self.type_g // + [classic::push_back_a(self.result_, self.type)] // + [clear_a(self.type)]; + typeList_p = '{' >> !type_p >> *(',' >> type_p) >> '}'; + } + + Rule const& start() const { + return typeList_p; + } + + }; +}; +// TypeListGrammar + +/* ************************************************************************* */ // Needed for other parsers in Argument.h and ReturnType.h static const bool T = true; diff --git a/wrap/tests/testType.cpp b/wrap/tests/testType.cpp index 7f165b109..1b55a1bb3 100644 --- a/wrap/tests/testType.cpp +++ b/wrap/tests/testType.cpp @@ -83,45 +83,6 @@ TEST( Type, grammar ) { actual.clear(); } -/* ************************************************************************* */ -// http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html -struct TypeListGrammar: public classic::grammar { - - typedef std::vector TypeList; - TypeList& result_; ///< successful parse will be placed in here - - mutable wrap::Qualified type; // temporary type for use during parsing - TypeGrammar type_g; - - /// Construct type grammar and specify where result is placed - TypeListGrammar(TypeList& result) : - result_(result), type_g(type) { - } - - /// Definition of type grammar - template - struct definition: basic_rules { - - typedef classic::rule Rule; - - Rule type_p, typeList_p; - - definition(TypeListGrammar const& self) { - using namespace classic; - type_p = self.type_g // - [classic::push_back_a(self.result_, self.type)] // - [clear_a(self.type)]; - typeList_p = '{' >> !type_p >> *(',' >> type_p) >> '}'; - } - - Rule const& start() const { - return typeList_p; - } - - }; -}; -// TypeListGrammar - //****************************************************************************** TEST( TypeList, grammar ) {