Tightened up individual Grammars
parent
08c9243acb
commit
e963512164
|
@ -129,7 +129,7 @@ struct ArgumentList: public std::vector<Argument> {
|
|||
struct ArgumentGrammar: public classic::grammar<ArgumentGrammar> {
|
||||
|
||||
wrap::Argument& result_; ///< successful parse will be placed in here
|
||||
TypeGrammar argument_type_g;
|
||||
TypeGrammar argument_type_g; ///< Type parser for Argument::type
|
||||
|
||||
/// Construct type grammar and specify where result is placed
|
||||
ArgumentGrammar(wrap::Argument& result) :
|
||||
|
@ -138,15 +138,13 @@ struct ArgumentGrammar: public classic::grammar<ArgumentGrammar> {
|
|||
|
||||
/// Definition of type grammar
|
||||
template<typename ScannerT>
|
||||
struct definition: basic_rules<ScannerT> {
|
||||
struct definition: BasicRules<ScannerT> {
|
||||
|
||||
typedef classic::rule<ScannerT> Rule;
|
||||
|
||||
Rule argument_p, argumentList_p;
|
||||
Rule argument_p;
|
||||
|
||||
definition(ArgumentGrammar const& self) {
|
||||
|
||||
using namespace wrap;
|
||||
using namespace classic;
|
||||
|
||||
// NOTE: allows for pointers to all types
|
||||
|
@ -156,7 +154,7 @@ struct ArgumentGrammar: public classic::grammar<ArgumentGrammar> {
|
|||
>> self.argument_type_g //
|
||||
>> !ch_p('*')[assign_a(self.result_.is_ptr, T)]
|
||||
>> !ch_p('&')[assign_a(self.result_.is_ref, T)]
|
||||
>> basic_rules<ScannerT>::name_p[assign_a(self.result_.name)];
|
||||
>> BasicRules<ScannerT>::name_p[assign_a(self.result_.name)];
|
||||
}
|
||||
|
||||
Rule const& start() const {
|
||||
|
@ -173,9 +171,9 @@ struct ArgumentListGrammar: public classic::grammar<ArgumentListGrammar> {
|
|||
|
||||
wrap::ArgumentList& result_; ///< successful parse will be placed in here
|
||||
|
||||
const Argument arg0; // used to reset arg
|
||||
mutable Argument arg; // temporary argument for use during parsing
|
||||
ArgumentGrammar argument_g;
|
||||
const Argument arg0; ///< used to reset arg
|
||||
mutable Argument arg; ///< temporary argument for use during parsing
|
||||
ArgumentGrammar argument_g; ///< single Argument parser
|
||||
|
||||
/// Construct type grammar and specify where result is placed
|
||||
ArgumentListGrammar(wrap::ArgumentList& result) :
|
||||
|
@ -184,21 +182,21 @@ struct ArgumentListGrammar: public classic::grammar<ArgumentListGrammar> {
|
|||
|
||||
/// Definition of type grammar
|
||||
template<typename ScannerT>
|
||||
struct definition: basic_rules<ScannerT> {
|
||||
struct definition {
|
||||
|
||||
typedef classic::rule<ScannerT> Rule;
|
||||
|
||||
Rule argument_p, argumentList_p;
|
||||
classic::rule<ScannerT> argument_p, argumentList_p;
|
||||
|
||||
definition(ArgumentListGrammar const& self) {
|
||||
using namespace classic;
|
||||
|
||||
argument_p = self.argument_g //
|
||||
[classic::push_back_a(self.result_, self.arg)] //
|
||||
[assign_a(self.arg, self.arg0)];
|
||||
|
||||
argumentList_p = '(' >> !argument_p >> *(',' >> argument_p) >> ')';
|
||||
}
|
||||
|
||||
Rule const& start() const {
|
||||
classic::rule<ScannerT> const& start() const {
|
||||
return argumentList_p;
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ void Module::parseMarkup(const std::string& data) {
|
|||
|
||||
// Define Rule and instantiate basic rules
|
||||
typedef rule<phrase_scanner_t> Rule;
|
||||
basic_rules<phrase_scanner_t> basic;
|
||||
BasicRules<phrase_scanner_t> basic;
|
||||
|
||||
// TODO, do we really need cls here? Non-local
|
||||
Class cls0(verbose),cls(verbose);
|
||||
|
|
|
@ -35,7 +35,7 @@ public:
|
|||
std::vector<std::string> namespaces_; ///< Stack of namespaces
|
||||
std::string name_; ///< type name
|
||||
|
||||
friend class TypeGrammar;
|
||||
friend struct TypeGrammar;
|
||||
friend class TemplateSubstitution;
|
||||
|
||||
public:
|
||||
|
@ -81,7 +81,7 @@ public:
|
|||
// Qualified is 'abused' as template argument name as well
|
||||
// this function checks whether *this matches with templateArg
|
||||
bool match(const std::string& templateArg) const {
|
||||
return (name_ == templateArg && namespaces_.empty());//TODO && category == CLASS);
|
||||
return (name_ == templateArg && namespaces_.empty()); //TODO && category == CLASS);
|
||||
}
|
||||
|
||||
void rename(const Qualified& q) {
|
||||
|
@ -128,7 +128,6 @@ public:
|
|||
return Qualified("void", VOID);
|
||||
}
|
||||
|
||||
|
||||
/// Return a qualified string using given delimiter
|
||||
std::string qualifiedName(const std::string& delimiter = "") const {
|
||||
std::string result;
|
||||
|
@ -156,12 +155,10 @@ public:
|
|||
|
||||
/* ************************************************************************* */
|
||||
// http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html
|
||||
class TypeGrammar: public classic::grammar<TypeGrammar> {
|
||||
struct TypeGrammar: classic::grammar<TypeGrammar> {
|
||||
|
||||
wrap::Qualified& result_; ///< successful parse will be placed in here
|
||||
|
||||
public:
|
||||
|
||||
/// Construct type grammar and specify where result is placed
|
||||
TypeGrammar(wrap::Qualified& result) :
|
||||
result_(result) {
|
||||
|
@ -169,17 +166,17 @@ public:
|
|||
|
||||
/// Definition of type grammar
|
||||
template<typename ScannerT>
|
||||
struct definition: basic_rules<ScannerT> {
|
||||
struct definition: BasicRules<ScannerT> {
|
||||
|
||||
typedef classic::rule<ScannerT> Rule;
|
||||
|
||||
Rule void_p, my_basisType_p, my_eigenType_p, namespace_del_p, class_p,
|
||||
type_p;
|
||||
Rule void_p, basisType_p, eigenType_p, namespace_del_p, class_p, type_p;
|
||||
|
||||
definition(TypeGrammar const& self) {
|
||||
|
||||
using namespace wrap;
|
||||
using namespace classic;
|
||||
typedef BasicRules<ScannerT> Basic;
|
||||
|
||||
// HACK: use const values instead of using enums themselves - somehow this doesn't result in values getting assigned to gibberish
|
||||
static const Qualified::Category EIGEN = Qualified::EIGEN;
|
||||
|
@ -187,25 +184,26 @@ public:
|
|||
static const Qualified::Category CLASS = Qualified::CLASS;
|
||||
static const Qualified::Category VOID = Qualified::VOID;
|
||||
|
||||
void_p = str_p("void")[assign_a(self.result_.name_)] //
|
||||
void_p = str_p("void") //
|
||||
[assign_a(self.result_.name_)] //
|
||||
[assign_a(self.result_.category, VOID)];
|
||||
|
||||
my_basisType_p = basic_rules<ScannerT>::basisType_p //
|
||||
basisType_p = Basic::basisType_p //
|
||||
[assign_a(self.result_.name_)] //
|
||||
[assign_a(self.result_.category, BASIS)];
|
||||
|
||||
my_eigenType_p = basic_rules<ScannerT>::eigenType_p //
|
||||
eigenType_p = Basic::eigenType_p //
|
||||
[assign_a(self.result_.name_)] //
|
||||
[assign_a(self.result_.category, EIGEN)];
|
||||
|
||||
namespace_del_p = basic_rules<ScannerT>::namespace_p //
|
||||
namespace_del_p = Basic::namespace_p //
|
||||
[push_back_a(self.result_.namespaces_)] >> str_p("::");
|
||||
|
||||
class_p = *namespace_del_p >> basic_rules<ScannerT>::className_p //
|
||||
class_p = *namespace_del_p >> Basic::className_p //
|
||||
[assign_a(self.result_.name_)] //
|
||||
[assign_a(self.result_.category, CLASS)];
|
||||
|
||||
type_p = void_p | my_basisType_p | class_p | my_eigenType_p;
|
||||
type_p = void_p | basisType_p | class_p | eigenType_p;
|
||||
}
|
||||
|
||||
Rule const& start() const {
|
||||
|
@ -218,8 +216,8 @@ public:
|
|||
|
||||
/* ************************************************************************* */
|
||||
// http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html
|
||||
template <char OPEN, char CLOSE>
|
||||
struct TypeListGrammar: public classic::grammar<TypeListGrammar<OPEN,CLOSE> > {
|
||||
template<char OPEN, char CLOSE>
|
||||
struct TypeListGrammar: public classic::grammar<TypeListGrammar<OPEN, CLOSE> > {
|
||||
|
||||
typedef std::vector<wrap::Qualified> TypeList;
|
||||
TypeList& result_; ///< successful parse will be placed in here
|
||||
|
@ -234,11 +232,9 @@ struct TypeListGrammar: public classic::grammar<TypeListGrammar<OPEN,CLOSE> > {
|
|||
|
||||
/// Definition of type grammar
|
||||
template<typename ScannerT>
|
||||
struct definition: basic_rules<ScannerT> {
|
||||
struct definition {
|
||||
|
||||
typedef classic::rule<ScannerT> Rule;
|
||||
|
||||
Rule type_p, typeList_p;
|
||||
classic::rule<ScannerT> type_p, typeList_p;
|
||||
|
||||
definition(TypeListGrammar const& self) {
|
||||
using namespace classic;
|
||||
|
@ -248,7 +244,7 @@ struct TypeListGrammar: public classic::grammar<TypeListGrammar<OPEN,CLOSE> > {
|
|||
typeList_p = OPEN >> !type_p >> *(',' >> type_p) >> CLOSE;
|
||||
}
|
||||
|
||||
Rule const& start() const {
|
||||
classic::rule<ScannerT> const& start() const {
|
||||
return typeList_p;
|
||||
}
|
||||
|
||||
|
@ -260,6 +256,5 @@ struct TypeListGrammar: public classic::grammar<TypeListGrammar<OPEN,CLOSE> > {
|
|||
// Needed for other parsers in Argument.h and ReturnType.h
|
||||
static const bool T = true;
|
||||
|
||||
|
||||
}// \namespace wrap
|
||||
} // \namespace wrap
|
||||
|
||||
|
|
|
@ -82,8 +82,7 @@ struct ReturnValue {
|
|||
struct ReturnValueGrammar: public classic::grammar<ReturnValueGrammar> {
|
||||
|
||||
wrap::ReturnValue& result_; ///< successful parse will be placed in here
|
||||
|
||||
ReturnTypeGrammar returnType1_g, returnType2_g;
|
||||
ReturnTypeGrammar returnType1_g, returnType2_g; ///< Type parsers
|
||||
|
||||
/// Construct type grammar and specify where result is placed
|
||||
ReturnValueGrammar(wrap::ReturnValue& result) :
|
||||
|
@ -97,7 +96,6 @@ struct ReturnValueGrammar: public classic::grammar<ReturnValueGrammar> {
|
|||
classic::rule<ScannerT> pair_p, returnValue_p;
|
||||
|
||||
definition(ReturnValueGrammar const& self) {
|
||||
|
||||
using namespace classic;
|
||||
|
||||
pair_p = (str_p("pair") >> '<' >> self.returnType1_g >> ','
|
||||
|
@ -114,4 +112,4 @@ struct ReturnValueGrammar: public classic::grammar<ReturnValueGrammar> {
|
|||
};
|
||||
// ReturnValueGrammar
|
||||
|
||||
} // \namespace wrap
|
||||
}// \namespace wrap
|
||||
|
|
|
@ -37,8 +37,7 @@ struct Template {
|
|||
struct TemplateGrammar: public classic::grammar<TemplateGrammar> {
|
||||
|
||||
Template& result_; ///< successful parse will be placed in here
|
||||
|
||||
TypeListGrammar<'{', '}'> argValues_g;
|
||||
TypeListGrammar<'{', '}'> argValues_g; ///< TypeList parser
|
||||
|
||||
/// Construct type grammar and specify where result is placed
|
||||
TemplateGrammar(Template& result) :
|
||||
|
@ -47,20 +46,18 @@ struct TemplateGrammar: public classic::grammar<TemplateGrammar> {
|
|||
|
||||
/// Definition of type grammar
|
||||
template<typename ScannerT>
|
||||
struct definition: basic_rules<ScannerT> {
|
||||
struct definition: BasicRules<ScannerT> {
|
||||
|
||||
typedef classic::rule<ScannerT> Rule;
|
||||
|
||||
Rule templateArgValues_p;
|
||||
classic::rule<ScannerT> templateArgValues_p;
|
||||
|
||||
definition(TemplateGrammar const& self) {
|
||||
using namespace classic;
|
||||
templateArgValues_p = (str_p("template") >> '<'
|
||||
>> (basic_rules<ScannerT>::name_p)[assign_a(self.result_.argName)]
|
||||
>> (BasicRules<ScannerT>::name_p)[assign_a(self.result_.argName)]
|
||||
>> '=' >> self.argValues_g >> '>');
|
||||
}
|
||||
|
||||
Rule const& start() const {
|
||||
classic::rule<ScannerT> const& start() const {
|
||||
return templateArgValues_p;
|
||||
}
|
||||
|
||||
|
|
|
@ -125,18 +125,18 @@ BOOST_SPIRIT_CLASSIC_NAMESPACE_END
|
|||
}
|
||||
}
|
||||
|
||||
namespace wrap {
|
||||
|
||||
namespace classic = BOOST_SPIRIT_CLASSIC_NS;
|
||||
|
||||
/// Some basic rules used by all parsers
|
||||
template<typename ScannerT>
|
||||
struct basic_rules {
|
||||
struct BasicRules {
|
||||
|
||||
typedef BOOST_SPIRIT_CLASSIC_NS::rule<ScannerT> Rule;
|
||||
classic::rule<ScannerT> comments_p, basisType_p, eigenType_p, keywords_p,
|
||||
stlType_p, name_p, className_p, namespace_p;
|
||||
|
||||
Rule comments_p, basisType_p, eigenType_p, keywords_p, stlType_p, name_p,
|
||||
className_p, namespace_p;
|
||||
|
||||
basic_rules() {
|
||||
BasicRules() {
|
||||
|
||||
using namespace BOOST_SPIRIT_CLASSIC_NS;
|
||||
|
||||
|
@ -160,5 +160,5 @@ struct basic_rules {
|
|||
namespace_p = lexeme_d[lower_p >> *(alnum_p | '_')] - keywords_p;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -65,8 +65,6 @@ TEST( Method, addOverload ) {
|
|||
// 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;
|
||||
|
|
Loading…
Reference in New Issue