Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r70820 - in trunk/boost/spirit/home: lex/lexer/lexertl lex/qi qi/detail
From: hartmut.kaiser_at_[hidden]
Date: 2011-04-01 12:02:28


Author: hkaiser
Date: 2011-04-01 12:02:27 EDT (Fri, 01 Apr 2011)
New Revision: 70820
URL: http://svn.boost.org/trac/boost/changeset/70820

Log:
Spirit: fixing lexer example6.cpp
Text files modified:
   trunk/boost/spirit/home/lex/lexer/lexertl/token.hpp | 3 +
   trunk/boost/spirit/home/lex/qi/plain_token.hpp | 10 ++++++++
   trunk/boost/spirit/home/lex/qi/plain_tokenid.hpp | 12 +++++++++
   trunk/boost/spirit/home/qi/detail/assign_to.hpp | 48 +++++++++++++++++++++++++++++++--------
   4 files changed, 61 insertions(+), 12 deletions(-)

Modified: trunk/boost/spirit/home/lex/lexer/lexertl/token.hpp
==============================================================================
--- trunk/boost/spirit/home/lex/lexer/lexertl/token.hpp (original)
+++ trunk/boost/spirit/home/lex/lexer/lexertl/token.hpp 2011-04-01 12:02:27 EDT (Fri, 01 Apr 2011)
@@ -479,7 +479,8 @@
 
                 typedef lex::lexertl::token<
                     Iterator, AttributeTypes, HasState, Idtype> token_type;
- const_cast<token_type&>(t).value() = attr; // re-assign value
+ spirit::traits::assign_to(
+ attr, const_cast<token_type&>(t).value()); // re-assign value
             }
             else {
             // reuse the already assigned value

Modified: trunk/boost/spirit/home/lex/qi/plain_token.hpp
==============================================================================
--- trunk/boost/spirit/home/lex/qi/plain_token.hpp (original)
+++ trunk/boost/spirit/home/lex/qi/plain_token.hpp 2011-04-01 12:02:27 EDT (Fri, 01 Apr 2011)
@@ -13,6 +13,7 @@
 #include <boost/spirit/home/support/info.hpp>
 #include <boost/spirit/home/qi/detail/attributes.hpp>
 #include <boost/spirit/home/support/common_terminals.hpp>
+#include <boost/spirit/home/support/handles_container.hpp>
 #include <boost/spirit/home/qi/skip_over.hpp>
 #include <boost/spirit/home/qi/domain.hpp>
 #include <boost/spirit/home/qi/parser.hpp>
@@ -136,4 +137,13 @@
     };
 }}}
 
+namespace boost { namespace spirit { namespace traits
+{
+ ///////////////////////////////////////////////////////////////////////////
+ template<typename Idtype, typename Attr, typename Context, typename Iterator>
+ struct handles_container<qi::plain_token<Idtype>, Attr, Context, Iterator>
+ : mpl::true_
+ {};
+}}}
+
 #endif

Modified: trunk/boost/spirit/home/lex/qi/plain_tokenid.hpp
==============================================================================
--- trunk/boost/spirit/home/lex/qi/plain_tokenid.hpp (original)
+++ trunk/boost/spirit/home/lex/qi/plain_tokenid.hpp 2011-04-01 12:02:27 EDT (Fri, 01 Apr 2011)
@@ -13,6 +13,7 @@
 #include <boost/spirit/home/support/info.hpp>
 #include <boost/spirit/home/qi/detail/attributes.hpp>
 #include <boost/spirit/home/support/common_terminals.hpp>
+#include <boost/spirit/home/support/handles_container.hpp>
 #include <boost/spirit/home/qi/skip_over.hpp>
 #include <boost/spirit/home/qi/domain.hpp>
 #include <boost/spirit/home/qi/parser.hpp>
@@ -115,7 +116,7 @@
     template <typename Modifiers>
     struct make_primitive<tag::tokenid, Modifiers>
     {
- typedef plain_token<std::size_t> result_type;
+ typedef plain_tokenid<std::size_t> result_type;
 
         result_type operator()(unused_type, unused_type) const
         {
@@ -137,4 +138,13 @@
     };
 }}}
 
+namespace boost { namespace spirit { namespace traits
+{
+ ///////////////////////////////////////////////////////////////////////////
+ template<typename Idtype, typename Attr, typename Context, typename Iterator>
+ struct handles_container<qi::plain_tokenid<Idtype>, Attr, Context, Iterator>
+ : mpl::true_
+ {};
+}}}
+
 #endif

Modified: trunk/boost/spirit/home/qi/detail/assign_to.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/detail/assign_to.hpp (original)
+++ trunk/boost/spirit/home/qi/detail/assign_to.hpp 2011-04-01 12:02:27 EDT (Fri, 01 Apr 2011)
@@ -60,6 +60,18 @@
         }
     };
 
+ template <typename Attribute, typename Iterator>
+ struct assign_to_attribute_from_iterators<
+ boost::optional<Attribute>, Iterator>
+ {
+ static void
+ call(Iterator const& first, Iterator const& last
+ , boost::optional<Attribute>& attr)
+ {
+ attr = Attribute(first, last);
+ }
+ };
+
     template <typename Iterator>
     struct assign_to_attribute_from_iterators<
         iterator_range<Iterator>, Iterator>
@@ -139,21 +151,24 @@
     };
 
     template <typename Attribute, typename T>
- struct assign_to_attribute_from_value<reference_wrapper<Attribute>, T>
+ struct assign_to_attribute_from_value<Attribute, reference_wrapper<T>
+ , typename disable_if<is_same<Attribute, reference_wrapper<T> > >::type>
     {
         static void
- call(T const& val, reference_wrapper<Attribute> attr)
+ call(reference_wrapper<T> const& val, Attribute& attr)
         {
             assign_to(val.get(), attr);
         }
     };
 
- template <typename Attribute>
- struct assign_to_attribute_from_value<boost::optional<Attribute>, unused_type>
+ template <typename Attribute, typename T>
+ struct assign_to_attribute_from_value<Attribute, boost::optional<T>
+ , typename disable_if<is_same<Attribute, boost::optional<T> > >::type>
     {
         static void
- call(unused_type, boost::optional<Attribute> const&)
+ call(boost::optional<T> const& val, Attribute& attr)
         {
+ assign_to(val.get(), attr);
         }
     };
 
@@ -270,22 +285,35 @@
         }
     };
 
+ template <typename Attribute>
+ struct assign_to_container_from_value<Attribute, Attribute>
+ {
+ static void
+ call(Attribute const& val, Attribute& attr)
+ {
+ attr = val;
+ }
+ };
+
     template <typename Attribute, typename T>
- struct assign_to_container_from_value<reference_wrapper<Attribute>, T>
+ struct assign_to_container_from_value<Attribute, boost::optional<T>
+ , typename disable_if<is_same<Attribute, boost::optional<T> > >::type>
     {
         static void
- call(T const& val, reference_wrapper<Attribute> attr)
+ call(boost::optional<T> const& val, Attribute& attr)
         {
             assign_to(val.get(), attr);
         }
     };
 
- template <typename Attribute>
- struct assign_to_container_from_value<boost::optional<Attribute>, unused_type>
+ template <typename Attribute, typename T>
+ struct assign_to_container_from_value<Attribute, reference_wrapper<T>
+ , typename disable_if<is_same<Attribute, reference_wrapper<T> > >::type>
     {
         static void
- call(unused_type, boost::optional<Attribute> const&)
+ call(reference_wrapper<T> const& val, Attribute& attr)
         {
+ assign_to(val.get(), attr);
         }
     };
 


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