|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r60670 - trunk/libs/spirit/optmization/qi
From: joel_at_[hidden]
Date: 2010-03-16 20:36:45
Author: djowel
Date: 2010-03-16 20:36:44 EDT (Tue, 16 Mar 2010)
New Revision: 60670
URL: http://svn.boost.org/trac/boost/changeset/60670
Log:
adding attribute vs action tests
Added:
trunk/libs/spirit/optmization/qi/attr_vs_actions.cpp (contents, props changed)
Text files modified:
trunk/libs/spirit/optmization/qi/Jamfile | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
Modified: trunk/libs/spirit/optmization/qi/Jamfile
==============================================================================
--- trunk/libs/spirit/optmization/qi/Jamfile (original)
+++ trunk/libs/spirit/optmization/qi/Jamfile 2010-03-16 20:36:44 EDT (Tue, 16 Mar 2010)
@@ -10,3 +10,4 @@
# performance tests
exe int_parser : int_parser.cpp ;
exe real_parser : real_parser.cpp ;
+exe attr_vs_actions : attr_vs_actions.cpp ;
Added: trunk/libs/spirit/optmization/qi/attr_vs_actions.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/optmization/qi/attr_vs_actions.cpp 2010-03-16 20:36:44 EDT (Tue, 16 Mar 2010)
@@ -0,0 +1,93 @@
+#include <boost/config/warning_disable.hpp>
+#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+#include <boost/spirit/include/phoenix_object.hpp>
+#include <boost/spirit/include/phoenix_stl.hpp>
+#include <boost/fusion/include/adapt_struct.hpp>
+#include <boost/fusion/include/io.hpp>
+
+#include <iostream>
+#include <string>
+#include <complex>
+
+using boost::spirit::qi::grammar;
+using boost::spirit::qi::rule;
+using boost::spirit::qi::char_;
+using boost::spirit::qi::parse;
+using boost::spirit::qi::_val;
+using boost::spirit::qi::_1;
+using boost::phoenix::push_back;
+
+#define ATTR_PROPAGATE
+
+struct test_attr
+{
+ test_attr()
+ {
+ std::cout << "default construct" << std::endl;
+ }
+
+ test_attr(char)
+ {
+ std::cout << "construct from char" << std::endl;
+ }
+
+ test_attr(test_attr const&)
+ {
+ std::cout << "copy construct" << std::endl;
+ }
+
+ test_attr& operator=(test_attr const&)
+ {
+ std::cout << "assign" << std::endl;
+ return *this;
+ }
+};
+
+template <typename Iterator>
+struct test_parser : grammar<Iterator, std::vector<test_attr>() >
+{
+ test_parser() : test_parser::base_type(start)
+ {
+#ifdef ATTR_PROPAGATE
+ start = char_ >> *(',' >> char_);
+#else
+ start = char_[push_back(_val, _1)] >> *(',' >> char_[push_back(_val, _1)]);
+#endif
+ }
+
+ rule<Iterator, std::vector<test_attr>()> start;
+};
+
+int main()
+{
+ typedef std::string::const_iterator iterator_type;
+ typedef test_parser<iterator_type> test_parser;
+
+ test_parser g;
+ std::string str = "a,b,c,d,e";
+
+ std::vector<test_attr> result;
+ result.reserve(20);
+ std::string::const_iterator iter = str.begin();
+ std::string::const_iterator end = str.end();
+ bool r = parse(iter, end, g, result);
+
+ if (r && iter == end)
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing succeeded\n";
+ std::cout << "\n-------------------------\n";
+ }
+ else
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing failed\n";
+ std::cout << "-------------------------\n";
+ }
+
+ std::cout << "Bye... :-) \n\n";
+ return 0;
+}
+
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk