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