Boost logo

Boost-Commit :

From: hartmut.kaiser_at_[hidden]
Date: 2008-05-06 19:59:25


Author: hkaiser
Date: 2008-05-06 19:59:24 EDT (Tue, 06 May 2008)
New Revision: 45185
URL: http://svn.boost.org/trac/boost/changeset/45185

Log:
Spirit.Karma: Fixed alternative generator
Text files modified:
   trunk/boost/spirit/home/karma/operator/alternative.hpp | 2 +-
   trunk/boost/spirit/home/karma/operator/detail/alternative.hpp | 32 +++++++++++++++++++++++++++++---
   trunk/libs/spirit/example/karma/mini_xml_karma.cpp | 2 +-
   3 files changed, 31 insertions(+), 5 deletions(-)

Modified: trunk/boost/spirit/home/karma/operator/alternative.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/operator/alternative.hpp (original)
+++ trunk/boost/spirit/home/karma/operator/alternative.hpp 2008-05-06 19:59:24 EDT (Tue, 06 May 2008)
@@ -46,7 +46,7 @@
 
         template <typename Component, typename Context, typename Iterator>
         struct attribute :
- build_fusion_sequence<alternative, Component, Iterator, Context, mpl::true_>
+ build_fusion_sequence<alternative, Component, Iterator, Context>
         {
         };
 

Modified: trunk/boost/spirit/home/karma/operator/detail/alternative.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/operator/detail/alternative.hpp (original)
+++ trunk/boost/spirit/home/karma/operator/detail/alternative.hpp 2008-05-06 19:59:24 EDT (Tue, 06 May 2008)
@@ -22,7 +22,12 @@
 #include <boost/type_traits/is_convertible.hpp>
 #include <boost/variant.hpp>
 
-namespace boost { namespace spirit { namespace karma { namespace detail
+namespace boost { namespace spirit { namespace karma
+{
+ ///////////////////////////////////////////////////////////////////////////
+ struct sequence; // forward declaration only
+
+namespace detail
 {
     ///////////////////////////////////////////////////////////////////////////
     // A component is compatible to a given parameter type if the parameter
@@ -38,12 +43,14 @@
         typedef typename
             mpl::find_if<
                 types,
- is_same<mpl::_1, Expected>
+ is_convertible<mpl::_1, Expected>
>::type
         iter;
 
         typedef typename mpl::not_<is_same<iter, end> >::type type;
         enum { value = type::value };
+
+
     };
 
     template <typename Expected>
@@ -108,6 +115,24 @@
>::type
>
     {
+ // If this alternative is a sequence, we wrap the attribute into a
+ // fusion sequence.
+ template <typename Parameter>
+ static fusion::vector<Parameter const&>
+ wrap_attribute(Parameter const& param, mpl::true_)
+ {
+ return fusion::vector<Parameter const&>(param);
+ }
+
+ // If this alternative is not a sequence the parameter is passed
+ // through unchanged.
+ template <typename Parameter>
+ static Parameter const&
+ wrap_attribute(Parameter const& param, mpl::false_)
+ {
+ return param;
+ }
+
         template <typename OutputIterator, typename Context, typename Delimiter>
         static bool
         call(Component const& component, OutputIterator& sink,
@@ -137,8 +162,9 @@
             compatible_type;
 
             typedef typename Component::director director;
+ typedef typename is_same<director, sequence>::type is_sequence;
             return director::generate(component, sink, ctx, delim,
- get<compatible_type>(param));
+ wrap_attribute(get<compatible_type>(param), is_sequence()));
         }
     };
 

Modified: trunk/libs/spirit/example/karma/mini_xml_karma.cpp
==============================================================================
--- trunk/libs/spirit/example/karma/mini_xml_karma.cpp (original)
+++ trunk/libs/spirit/example/karma/mini_xml_karma.cpp 2008-05-06 19:59:24 EDT (Tue, 06 May 2008)
@@ -134,7 +134,7 @@
     {
         node %=
                 lit[_1 = _string(_r0)]
- | (char_('\n') << xml[_1 = _xml(_r0)] << '\n')
+ | xml[_1 = _xml(_r0)]
             ;
 
         xml = char_('<') << lit(at_c<0>(_r0)) << '>'


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