Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58695 - in trunk/boost/spirit/home: karma/auto support
From: hartmut.kaiser_at_[hidden]
Date: 2010-01-04 20:03:15


Author: hkaiser
Date: 2010-01-04 20:03:15 EST (Mon, 04 Jan 2010)
New Revision: 58695
URL: http://svn.boost.org/trac/boost/changeset/58695

Log:
Spirit: added karma::auto_()
Text files modified:
   trunk/boost/spirit/home/karma/auto/auto.hpp | 79 ++++++++++++++++++++++++++++++++++++++++
   trunk/boost/spirit/home/support/common_terminals.hpp | 2
   2 files changed, 80 insertions(+), 1 deletions(-)

Modified: trunk/boost/spirit/home/karma/auto/auto.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/auto/auto.hpp (original)
+++ trunk/boost/spirit/home/karma/auto/auto.hpp 2010-01-04 20:03:15 EST (Mon, 04 Jan 2010)
@@ -31,12 +31,24 @@
     template <>
     struct use_terminal<karma::domain, tag::auto_> // enables auto_
       : mpl::true_ {};
+
+ template <typename A0>
+ struct use_terminal<karma::domain // enables auto_(...)
+ , terminal_ex<tag::auto_, fusion::vector1<A0> >
+ > : mpl::true_ {};
+
+ template <> // enables auto_(f)
+ struct use_lazy_terminal<
+ karma::domain, tag::auto_, 1 /*arity*/
+ > : mpl::true_ {};
+
 }}
 
 ///////////////////////////////////////////////////////////////////////////////
 namespace boost { namespace spirit { namespace karma
 {
     using spirit::auto_;
+ using spirit::auto__type;
 
     ///////////////////////////////////////////////////////////////////////////
     template <typename Modifiers>
@@ -90,8 +102,58 @@
     };
 
     ///////////////////////////////////////////////////////////////////////////
+ template <typename T, typename Modifiers>
+ struct lit_auto_generator
+ : generator<lit_auto_generator<T, Modifiers> >
+ {
+ typedef mpl::int_<generator_properties::all_properties> properties;
+
+ template <typename Context, typename Unused>
+ struct attribute
+ {
+ typedef unused_type type;
+ };
+
+ lit_auto_generator(typename add_reference<T>::type t, Modifiers const& modifiers)
+ : t_(t)
+ , generator_(compile<karma::domain>(create_generator<T>(), modifiers))
+ {}
+
+ // auto_generator has an attached attribute
+ template <
+ typename OutputIterator, typename Context, typename Delimiter
+ , typename Attribute>
+ bool generate(OutputIterator& sink, Context& context
+ , Delimiter const& d, Attribute const&) const
+ {
+ return generator_.generate(sink, context, d, t_);
+ }
+
+ template <typename Context>
+ info what(Context& /*context*/) const
+ {
+ return info("auto_");
+ }
+
+ typedef typename spirit::result_of::create_generator<T>::type
+ generator_type;
+
+ typedef typename spirit::result_of::compile<
+ karma::domain, generator_type, Modifiers>::type generator_impl_type;
+
+ T t_;
+ generator_impl_type generator_;
+
+ private:
+ // silence MSVC warning C4512: assignment operator could not be generated
+ lit_auto_generator& operator= (lit_auto_generator const&);
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
     // Generator generators: make_xxx function (objects)
     ///////////////////////////////////////////////////////////////////////////
+
+ // auto_
     template <typename Modifiers>
     struct make_primitive<tag::auto_, Modifiers>
     {
@@ -102,6 +164,23 @@
             return result_type(modifiers);
         }
     };
+
+ // auto_(...)
+ template <typename Modifiers, typename A0>
+ struct make_primitive<
+ terminal_ex<tag::auto_, fusion::vector1<A0> >, Modifiers>
+ {
+ typedef typename add_const<A0>::type const_attribute;
+
+ typedef lit_auto_generator<const_attribute, Modifiers> result_type;
+
+ template <typename Terminal>
+ result_type operator()(Terminal const& term, Modifiers const& modifiers) const
+ {
+ return result_type(fusion::at_c<0>(term.args), modifiers);
+ }
+ };
+
 }}}
 
 #endif

Modified: trunk/boost/spirit/home/support/common_terminals.hpp
==============================================================================
--- trunk/boost/spirit/home/support/common_terminals.hpp (original)
+++ trunk/boost/spirit/home/support/common_terminals.hpp 2010-01-04 20:03:15 EST (Mon, 04 Jan 2010)
@@ -33,7 +33,6 @@
         ( buffer )
         ( true_ )
         ( false_ )
- ( auto_ )
     )
 
     // Here we are reusing proto::lit
@@ -82,6 +81,7 @@
         ( token )
         ( attr )
         ( columns )
+ ( auto_ )
     )
 
     // special tags (used mainly for stateful tag types)


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