Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67392 - in trunk: boost/spirit/home/support/utree libs/spirit/test/qi
From: admin_at_[hidden]
Date: 2010-12-21 14:54:15


Author: wash
Date: 2010-12-21 14:54:14 EST (Tue, 21 Dec 2010)
New Revision: 67392
URL: http://svn.boost.org/trac/boost/changeset/67392

Log:
Added a new utree CP to allow rule<Iterator, utf8_string_type()> r = char("+-/*")
semantics (rationale: a single character is represented as a string in utree).
Also added tests for the above functionality.

Text files modified:
   trunk/boost/spirit/home/support/utree/utree_traits.hpp | 13 +++++++++++++
   trunk/libs/spirit/test/qi/utree.cpp | 15 +++++++++++++++
   2 files changed, 28 insertions(+), 0 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-21 14:54:14 EST (Tue, 21 Dec 2010)
@@ -197,6 +197,19 @@
     };
 
     ///////////////////////////////////////////////////////////////////////////
+ // this specialization allows the use of char("+-/*")
+ template<typename T, typename Traits, typename Allocator, utree_type::info I>
+ struct assign_to_attribute_from_value<spirit::basic_string<std::basic_string<T, Traits, Allocator>, I>, char>
+ {
+ typedef spirit::basic_string<std::basic_string<T, Traits, Allocator>, I> attribute;
+
+ static void call (char val, attribute& attr)
+ {
+ attr.assign(1, val);
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
     // Karma only: convert utree node to string
     template <>
     struct attribute_as_string<utree>

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-21 14:54:14 EST (Tue, 21 Dec 2010)
@@ -63,6 +63,21 @@
             ut.which() == utree_type::symbol_type && check(ut, "xyz"));
     }
 
+ // char set tests
+ {
+ utree ut;
+ rule<char const*, utf8_string_type()> r1 = char_("abc");
+
+ BOOST_TEST(test_attr("a", r1, 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, "+"));
+ }
+
     // sequences
     {
         using boost::spirit::qi::digit;


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