Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69292 - in trunk/boost/spirit/home: karma qi support
From: hartmut.kaiser_at_[hidden]
Date: 2011-02-25 23:05:16


Author: hkaiser
Date: 2011-02-25 23:05:11 EST (Fri, 25 Feb 2011)
New Revision: 69292
URL: http://svn.boost.org/trac/boost/changeset/69292

Log:
Spirit: added context to top level APIs
Text files modified:
   trunk/boost/spirit/home/karma/generate.hpp | 50 ++++++++++++++++++++++++++++------------
   trunk/boost/spirit/home/qi/parse.hpp | 23 ++++++++++++++++-
   trunk/boost/spirit/home/support/context.hpp | 3 -
   3 files changed, 57 insertions(+), 19 deletions(-)

Modified: trunk/boost/spirit/home/karma/generate.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/generate.hpp (original)
+++ trunk/boost/spirit/home/karma/generate.hpp 2011-02-25 23:05:11 EST (Fri, 25 Feb 2011)
@@ -10,6 +10,8 @@
 #pragma once
 #endif
 
+#include <boost/spirit/home/support/context.hpp>
+#include <boost/spirit/home/support/nonterminal/locals.hpp>
 #include <boost/spirit/home/karma/detail/generate.hpp>
 
 namespace boost { namespace spirit { namespace karma
@@ -35,10 +37,26 @@
     }
 
     ///////////////////////////////////////////////////////////////////////////
- template <typename OutputIterator, typename Expr, typename Attr>
+ namespace detail
+ {
+ template <typename T>
+ struct make_context
+ {
+ typedef context<fusion::cons<T const&>, locals<> > type;
+ };
+
+ template <>
+ struct make_context<unused_type>
+ {
+ typedef unused_type type;
+ };
+ }
+
+ template <typename OutputIterator, typename Properties, typename Expr
+ , typename Attr>
     inline bool
     generate(
- OutputIterator& sink_
+ detail::output_iterator<OutputIterator, Properties>& sink
       , Expr const& expr
       , Attr const& attr)
     {
@@ -47,21 +65,14 @@
         // then the expression (expr) is not a valid spirit karma expression.
         BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
 
- typedef traits::properties_of<
- typename result_of::compile<karma::domain, Expr>::type
- > properties;
-
- // wrap user supplied iterator into our own output iterator
- detail::output_iterator<OutputIterator
- , mpl::int_<properties::value> > sink(sink_);
- return compile<karma::domain>(expr).generate(sink, unused, unused, attr);
+ typename detail::make_context<Attr>::type context(attr);
+ return compile<karma::domain>(expr).generate(sink, context, unused, attr);
     }
 
- template <typename OutputIterator, typename Properties, typename Expr
- , typename Attr>
+ template <typename OutputIterator, typename Expr, typename Attr>
     inline bool
     generate(
- detail::output_iterator<OutputIterator, Properties>& sink
+ OutputIterator& sink_
       , Expr const& expr
       , Attr const& attr)
     {
@@ -70,7 +81,14 @@
         // then the expression (expr) is not a valid spirit karma expression.
         BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
 
- return compile<karma::domain>(expr).generate(sink, unused, unused, attr);
+ typedef traits::properties_of<
+ typename result_of::compile<karma::domain, Expr>::type
+ > properties;
+
+ // wrap user supplied iterator into our own output iterator
+ detail::output_iterator<OutputIterator
+ , mpl::int_<properties::value> > sink(sink_);
+ return generate(sink, expr, attr);
     }
 
     template <typename OutputIterator, typename Expr, typename Attr>
@@ -137,8 +155,10 @@
         {
             return false;
         }
+
+ typename detail::make_context<Attribute>::type context(attr);
         return compile<karma::domain>(expr).
- generate(sink, unused, delimiter_, attr);
+ generate(sink, context, delimiter_, attr);
     }
 
     template <typename OutputIterator, typename Expr, typename Delimiter

Modified: trunk/boost/spirit/home/qi/parse.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/parse.hpp (original)
+++ trunk/boost/spirit/home/qi/parse.hpp 2011-02-25 23:05:11 EST (Fri, 25 Feb 2011)
@@ -12,6 +12,8 @@
 #pragma once
 #endif
 
+#include <boost/spirit/home/support/context.hpp>
+#include <boost/spirit/home/support/nonterminal/locals.hpp>
 #include <boost/spirit/home/qi/detail/parse.hpp>
 #include <boost/concept_check.hpp>
 
@@ -46,6 +48,21 @@
     }
 
     ///////////////////////////////////////////////////////////////////////////
+ namespace detail
+ {
+ template <typename T>
+ struct make_context
+ {
+ typedef context<fusion::cons<T&>, locals<> > type;
+ };
+
+ template <>
+ struct make_context<unused_type>
+ {
+ typedef unused_type type;
+ };
+ }
+
     template <typename Iterator, typename Expr, typename Attr>
     inline bool
     parse(
@@ -65,7 +82,8 @@
         // then the expression (expr) is not a valid spirit qi expression.
         BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
 
- return compile<qi::domain>(expr).parse(first, last, unused, unused, attr);
+ typename detail::make_context<Attr>::type context(attr);
+ return compile<qi::domain>(expr).parse(first, last, context, unused, attr);
     }
 
     template <typename Iterator, typename Expr, typename Attr>
@@ -142,8 +160,9 @@
         skipper_type;
         skipper_type const skipper_ = compile<qi::domain>(skipper);
 
+ typename detail::make_context<Attr>::type context(attr);
         if (!compile<qi::domain>(expr).parse(
- first, last, unused, skipper_, attr))
+ first, last, context, skipper_, attr))
             return false;
 
         if (post_skip == skip_flag::postskip)

Modified: trunk/boost/spirit/home/support/context.hpp
==============================================================================
--- trunk/boost/spirit/home/support/context.hpp (original)
+++ trunk/boost/spirit/home/support/context.hpp 2011-02-25 23:05:11 EST (Fri, 25 Feb 2011)
@@ -14,6 +14,7 @@
 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
 #include <boost/spirit/home/support/nonterminal/expand_arg.hpp>
 #include <boost/spirit/home/support/assert_msg.hpp>
+#include <boost/spirit/home/support/argument.hpp>
 #include <boost/spirit/home/phoenix/core/actor.hpp>
 #include <boost/spirit/home/phoenix/core/argument.hpp>
 #include <boost/fusion/include/at.hpp>
@@ -249,8 +250,6 @@
         using spirit::_j;
 #endif
     }
-
-
 }}
 
 #endif


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