Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67409 - in trunk: boost/spirit/home/support/utree libs/spirit/test/qi
From: admin_at_[hidden]
Date: 2010-12-22 00:20:06


Author: wash
Date: 2010-12-22 00:20:00 EST (Wed, 22 Dec 2010)
New Revision: 67409
URL: http://svn.boost.org/trac/boost/changeset/67409

Log:
Removed the typed string CP, add a fix for sequences, and some new tests for
them.

Text files modified:
   trunk/boost/spirit/home/support/utree/utree_traits.hpp | 24 +++++++-----------------
   trunk/libs/spirit/test/qi/utree.cpp | 35 +++++++++++++++++++++--------------
   2 files changed, 28 insertions(+), 31 deletions(-)

Modified: trunk/boost/spirit/home/support/utree/utree_traits.hpp
==============================================================================
--- trunk/boost/spirit/home/support/utree/utree_traits.hpp (original)
+++ trunk/boost/spirit/home/support/utree/utree_traits.hpp 2010-12-22 00:20:00 EST (Wed, 22 Dec 2010)
@@ -220,22 +220,6 @@
     };
 
     ///////////////////////////////////////////////////////////////////////////
- // this specialization allows the use of utree as the attribute for single
- // character parsers
- // FIXME: should we leave that in?
- template<utree_type::info I>
- struct assign_to_attribute_from_value<
- spirit::basic_string<std::string, I>, char>
- {
- typedef spirit::basic_string<std::string, I> attribute_type;
-
- static void call (char val, attribute_type& attr)
- {
- attr.assign(1, val);
- }
- };
-
- ///////////////////////////////////////////////////////////////////////////
     // this specialization tells Spirit.Qi to allow assignment to an utree from
     // generic iterators
     template <typename Iterator>
@@ -244,7 +228,13 @@
         static void
         call(Iterator const& first, Iterator const& last, utree& attr)
         {
- attr.assign(first, last);
+ if (attr.empty())
+ attr.assign(first, last);
+ else
+ for (Iterator it = first; it != last; ++it)
+ {
+ push_back(attr, *it);
+ }
         }
     };
 

Modified: trunk/libs/spirit/test/qi/utree.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/utree.cpp (original)
+++ trunk/libs/spirit/test/qi/utree.cpp 2010-12-22 00:20:00 EST (Wed, 22 Dec 2010)
@@ -31,13 +31,13 @@
     using boost::spirit::utf8_string_type;
 
     using boost::spirit::qi::char_;
+ using boost::spirit::qi::string;
     using boost::spirit::qi::int_;
     using boost::spirit::qi::double_;
     using boost::spirit::qi::space;
     using boost::spirit::qi::rule;
     using boost::spirit::qi::as_string;
     using boost::spirit::qi::lexeme;
- using boost::spirit::qi::as_string;
 
     // primitive data types
     {
@@ -64,20 +64,13 @@
             ut.which() == utree_type::symbol_type && check(ut, "xyz"));
     }
 
- // single character parsers, FIXME: should we leave that in?
+ // single character parsers
     {
         utree ut;
- rule<char const*, utf8_string_type()> r1 = char_("abc");
+ rule<char const*, utree()> r = char_("abc");
 
- BOOST_TEST(test_attr("a", r1, ut) &&
+ BOOST_TEST(test_attr("a", r, ut) &&
             ut.which() == utree_type::string_type && check(ut, "\"a\""));
- ut.clear();
-
- rule<char const*, utf8_symbol_type()> r2 = char_("+-/*");
-
- BOOST_TEST(test_attr("+", r2, ut) &&
- ut.which() == utree_type::symbol_type && check(ut, "+"));
- ut.clear();
     }
 
     // sequences
@@ -101,14 +94,28 @@
         BOOST_TEST(test_attr("ab1.2", *~digit >> double_, ut) &&
             ut.which() == utree_type::list_type && check(ut, "( \"a\" \"b\" 1.2 )"));
 
- rule<char const*, utree()> r = double_;
+ rule<char const*, utree()> r1 = double_;
 
         ut.clear();
- BOOST_TEST(test_attr("1.2ab", r >> *char_, ut) &&
+ BOOST_TEST(test_attr("1.2ab", r1 >> *char_, ut) &&
             ut.which() == utree_type::list_type && check(ut, "( 1.2 \"a\" \"b\" )"));
         ut.clear();
- BOOST_TEST(test_attr("ab1.2", *~digit >> r, ut) &&
+ BOOST_TEST(test_attr("ab1.2", *~digit >> r1, ut) &&
             ut.which() == utree_type::list_type && check(ut, "( \"a\" \"b\" 1.2 )"));
+ ut.clear();
+
+ rule<char const*, utree()> r2 = int_ >> char_("!") >> double_;
+
+ BOOST_TEST(test_attr("17!3.14", r2, ut) &&
+ ut.which() == utree_type::list_type && check(ut, "( 17 \"!\" 3.14 )"));
+ ut.clear();
+
+ rule<char const*, utree()> r3 = double_ >> as_string[string("foo")] >> int_;
+
+ BOOST_TEST(test_attr("0.5foo5", r3, ut) &&
+ ut.which() == utree_type::list_type && check(ut, "( 0.5 \"foo\" 5 )"));
+
+ ut.clear();
     }
 
     // kleene star


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