ReturnType grammar
parent
dc42773f1e
commit
c661329ac1
|
@ -22,6 +22,8 @@ struct ReturnType: public Qualified {
|
||||||
|
|
||||||
bool isPtr;
|
bool isPtr;
|
||||||
|
|
||||||
|
friend struct ReturnValueGrammar;
|
||||||
|
|
||||||
/// Makes a void type
|
/// Makes a void type
|
||||||
ReturnType() :
|
ReturnType() :
|
||||||
isPtr(false) {
|
isPtr(false) {
|
||||||
|
|
|
@ -25,6 +25,8 @@ struct ReturnValue {
|
||||||
bool isPair;
|
bool isPair;
|
||||||
ReturnType type1, type2;
|
ReturnType type1, type2;
|
||||||
|
|
||||||
|
friend struct ReturnValueGrammar;
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
ReturnValue() :
|
ReturnValue() :
|
||||||
isPair(false) {
|
isPair(false) {
|
||||||
|
|
|
@ -34,13 +34,71 @@ TEST( ReturnType, Constructor1 ) {
|
||||||
|
|
||||||
//******************************************************************************
|
//******************************************************************************
|
||||||
TEST( ReturnType, Constructor2 ) {
|
TEST( ReturnType, Constructor2 ) {
|
||||||
ReturnType actual("Point3",Qualified::CLASS, true);
|
ReturnType actual("Point3", Qualified::CLASS, true);
|
||||||
EXPECT(actual.namespaces().empty());
|
EXPECT(actual.namespaces().empty());
|
||||||
EXPECT(actual.name()=="Point3");
|
EXPECT(actual.name()=="Point3");
|
||||||
EXPECT(actual.category==Qualified::CLASS);
|
EXPECT(actual.category==Qualified::CLASS);
|
||||||
EXPECT(actual.isPtr);
|
EXPECT(actual.isPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//******************************************************************************
|
||||||
|
// http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html
|
||||||
|
struct ReturnTypeGrammar: public classic::grammar<ReturnTypeGrammar> {
|
||||||
|
|
||||||
|
wrap::ReturnType& result_; ///< successful parse will be placed in here
|
||||||
|
|
||||||
|
TypeGrammar type_g;
|
||||||
|
|
||||||
|
/// Construct ReturnType grammar and specify where result is placed
|
||||||
|
ReturnTypeGrammar(wrap::ReturnType& result) :
|
||||||
|
result_(result), type_g(result_) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Definition of type grammar
|
||||||
|
template<typename ScannerT>
|
||||||
|
struct definition {
|
||||||
|
|
||||||
|
classic::rule<ScannerT> type_p;
|
||||||
|
|
||||||
|
definition(ReturnTypeGrammar const& self) {
|
||||||
|
using namespace classic;
|
||||||
|
type_p = self.type_g >> !ch_p('*')[assign_a(self.result_.isPtr, T)];
|
||||||
|
}
|
||||||
|
|
||||||
|
classic::rule<ScannerT> const& start() const {
|
||||||
|
return type_p;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
};
|
||||||
|
// ReturnTypeGrammar
|
||||||
|
|
||||||
|
//******************************************************************************
|
||||||
|
TEST( ReturnType, grammar ) {
|
||||||
|
|
||||||
|
using classic::space_p;
|
||||||
|
|
||||||
|
// Create type grammar that will place result in actual
|
||||||
|
ReturnType actual;
|
||||||
|
ReturnTypeGrammar g(actual);
|
||||||
|
|
||||||
|
EXPECT(parse("Point3", g, space_p).full);
|
||||||
|
EXPECT( actual==ReturnType("Point3"));
|
||||||
|
actual.clear();
|
||||||
|
|
||||||
|
EXPECT(parse("Test*", g, space_p).full);
|
||||||
|
EXPECT( actual==ReturnType("Test",Qualified::CLASS,true));
|
||||||
|
actual.clear();
|
||||||
|
|
||||||
|
EXPECT(parse("VectorNotEigen", g, space_p).full);
|
||||||
|
EXPECT(actual==ReturnType("VectorNotEigen"));
|
||||||
|
actual.clear();
|
||||||
|
|
||||||
|
EXPECT(parse("double", g, space_p).full);
|
||||||
|
EXPECT(actual==ReturnType("double",Qualified::BASIS));
|
||||||
|
actual.clear();
|
||||||
|
}
|
||||||
|
|
||||||
//******************************************************************************
|
//******************************************************************************
|
||||||
TEST( ReturnValue, Constructor ) {
|
TEST( ReturnValue, Constructor ) {
|
||||||
ReturnValue actual(ReturnType("Point2"), ReturnType("Point3"));
|
ReturnValue actual(ReturnType("Point2"), ReturnType("Point3"));
|
||||||
|
@ -55,7 +113,7 @@ 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
|
||||||
|
|
||||||
TypeGrammar returnType1_g, returnType2_g;
|
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 +155,16 @@ TEST( ReturnValue, grammar ) {
|
||||||
|
|
||||||
EXPECT(parse("pair<Point2,Point3>", g, space_p).full);
|
EXPECT(parse("pair<Point2,Point3>", g, space_p).full);
|
||||||
EXPECT( actual==ReturnValue(ReturnType("Point2"),ReturnType("Point3")));
|
EXPECT( actual==ReturnValue(ReturnType("Point2"),ReturnType("Point3")));
|
||||||
cout << actual << endl;
|
actual.clear();
|
||||||
|
|
||||||
|
EXPECT(parse("pair<Test*,Test>", g, space_p).full);
|
||||||
|
EXPECT( actual==ReturnValue( //
|
||||||
|
ReturnType("Test",Qualified::CLASS,true),ReturnType("Test")));
|
||||||
|
actual.clear();
|
||||||
|
|
||||||
|
EXPECT(parse("pair<Test,Test*>", g, space_p).full);
|
||||||
|
EXPECT( actual==ReturnValue(ReturnType("Test"), //
|
||||||
|
ReturnType("Test",Qualified::CLASS,true)));
|
||||||
actual.clear();
|
actual.clear();
|
||||||
|
|
||||||
EXPECT(parse("VectorNotEigen", g, space_p).full);
|
EXPECT(parse("VectorNotEigen", g, space_p).full);
|
||||||
|
|
Loading…
Reference in New Issue