Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55235 - in trunk/boost/spirit/home: karma/nonterminal qi/detail qi/directive qi/nonterminal qi/operator
From: hartmut.kaiser_at_[hidden]
Date: 2009-07-30 14:44:07


Author: hkaiser
Date: 2009-07-28 13:34:13 EDT (Tue, 28 Jul 2009)
New Revision: 55235
URL: http://svn.boost.org/trac/boost/changeset/55235

Log:
Spirit: added rule constructors allowing to directly initialize rules: rule<> r = ... (yay!), added proper initialization of attributes in looping parsers, fixed attribute passing for qi::rule's
Text files modified:
   trunk/boost/spirit/home/karma/nonterminal/rule.hpp | 23 ++++++++++++++++++-----
   trunk/boost/spirit/home/qi/detail/pass_container.hpp | 3 +--
   trunk/boost/spirit/home/qi/directive/repeat.hpp | 3 ++-
   trunk/boost/spirit/home/qi/nonterminal/rule.hpp | 29 ++++++++++++++++++++++-------
   trunk/boost/spirit/home/qi/operator/kleene.hpp | 3 ++-
   trunk/boost/spirit/home/qi/operator/list.hpp | 3 ++-
   trunk/boost/spirit/home/qi/operator/plus.hpp | 3 ++-
   7 files changed, 49 insertions(+), 18 deletions(-)

Modified: trunk/boost/spirit/home/karma/nonterminal/rule.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/nonterminal/rule.hpp (original)
+++ trunk/boost/spirit/home/karma/nonterminal/rule.hpp 2009-07-28 13:34:13 EDT (Tue, 28 Jul 2009)
@@ -184,12 +184,25 @@
         }
 
         rule(rule const& rhs)
- : base_type(terminal::make(alias()))
+ : base_type(rhs)
           , name_(rhs.name_)
           , f(rhs.f)
         {
         }
 
+ template <typename Expr>
+ rule (Expr const& expr, std::string const& name_ = "unnamed-rule")
+ : base_type(terminal::make(alias()))
+ , name_(name_)
+ {
+ // Report invalid expression error as early as possible.
+ // If you got an error_invalid_expression error message here, then
+ // the expression (expr) is not a valid spirit karma expression.
+ BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
+
+ f = detail::bind_generator<mpl::true_>(compile<karma::domain>(expr));
+ }
+
         rule& operator=(rule const& rhs)
         {
             // The following assertion fires when you try to initialize a rule
@@ -217,8 +230,8 @@
         rule& operator=(Expr const& expr)
         {
             // Report invalid expression error as early as possible.
- // If you got an error_invalid_expression error message here,
- // then the expression (expr) is not a valid spirit karma expression.
+ // If you got an error_invalid_expression error message here, then
+ // the expression (expr) is not a valid spirit karma expression.
             BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
 
             f = detail::bind_generator<mpl::false_>(compile<karma::domain>(expr));
@@ -230,8 +243,8 @@
         friend rule& operator%=(rule& r, Expr const& expr)
         {
             // Report invalid expression error as early as possible.
- // If you got an error_invalid_expression error message here,
- // then the expression (expr) is not a valid spirit karma expression.
+ // If you got an error_invalid_expression error message here, then
+ // the expression (expr) is not a valid spirit karma expression.
             BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
 
             r.f = detail::bind_generator<mpl::true_>(compile<karma::domain>(expr));

Modified: trunk/boost/spirit/home/qi/detail/pass_container.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/detail/pass_container.hpp (original)
+++ trunk/boost/spirit/home/qi/detail/pass_container.hpp 2009-07-28 13:34:13 EDT (Tue, 28 Jul 2009)
@@ -139,13 +139,12 @@
             return f(component, attr);
         }
 
- // Dispachtes to dispatch_main depending on the attribute type
+ // Dispaches to dispatch_main depending on the attribute type
         // of the Component
         template <typename Component>
         bool operator()(Component const& component) const
         {
             typedef typename traits::result_of::value<Attr>::type lhs;
- typedef typename F::context_type context_type;
             typedef typename traits::attribute_of<
                 Component, context_type, iterator_type>::type
             rhs_attribute;

Modified: trunk/boost/spirit/home/qi/directive/repeat.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/directive/repeat.hpp (original)
+++ trunk/boost/spirit/home/qi/directive/repeat.hpp 2009-07-28 13:34:13 EDT (Tue, 28 Jul 2009)
@@ -143,7 +143,8 @@
           , Attribute& attr) const
         {
             // create a local value if Attribute is not unused_type
- typename traits::result_of::value<Attribute>::type val;
+ typename traits::result_of::value<Attribute>::type val =
+ traits::result_of::value<Attribute>::type();
             typename LoopIter::type i = iter.start();
 
             // parse the minimum required

Modified: trunk/boost/spirit/home/qi/nonterminal/rule.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/nonterminal/rule.hpp (original)
+++ trunk/boost/spirit/home/qi/nonterminal/rule.hpp 2009-07-28 13:34:13 EDT (Tue, 28 Jul 2009)
@@ -177,12 +177,25 @@
         }
 
         rule(rule const& rhs)
- : base_type(terminal::make(alias()))
+ : base_type(rhs)
           , name_(rhs.name_)
           , f(rhs.f)
         {
         }
 
+ template <typename Expr>
+ rule (Expr const& expr, std::string const& name_ = "unnamed-rule")
+ : base_type(terminal::make(alias()))
+ , name_(name_)
+ {
+ // Report invalid expression error as early as possible.
+ // If you got an error_invalid_expression error message here,
+ // then the expression (expr) is not a valid spirit qi expression.
+ BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
+
+ f = detail::bind_parser<mpl::true_>(compile<qi::domain>(expr));
+ }
+
         rule& operator=(rule const& rhs)
         {
             // The following assertion fires when you try to initialize a rule
@@ -251,8 +264,10 @@
         {
             if (f)
             {
- value_initialized<attr_type> val;
- context_type context(val);
+ typedef traits::make_attribute<attr_type, Attribute> make_attribute;
+
+ typename make_attribute::type attr_ = make_attribute::call(attr);
+ context_type context(attr_);
 
                 // If you are seeing a compilation error here stating that the
                 // forth parameter can't be converted to a qi::reference
@@ -260,7 +275,6 @@
                 // an incompatible skipper type.
                 if (f(first, last, context, skipper))
                 {
- traits::swap_impl(attr, boost::get(val));
                     return true;
                 }
             }
@@ -275,8 +289,10 @@
         {
             if (f)
             {
- value_initialized<attr_type> val;
- context_type context(val, params, caller_context);
+ typedef traits::make_attribute<attr_type, Attribute> make_attribute;
+
+ typename make_attribute::type attr_ = make_attribute::call(attr);
+ context_type context(attr_, params, caller_context);
 
                 // If you are seeing a compilation error here stating that the
                 // forth parameter can't be converted to a qi::reference
@@ -284,7 +300,6 @@
                 // an incompatible skipper type.
                 if (f(first, last, context, skipper))
                 {
- traits::swap_impl(attr, boost::get(val));
                     return true;
                 }
             }

Modified: trunk/boost/spirit/home/qi/operator/kleene.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/operator/kleene.hpp (original)
+++ trunk/boost/spirit/home/qi/operator/kleene.hpp 2009-07-28 13:34:13 EDT (Tue, 28 Jul 2009)
@@ -58,7 +58,8 @@
           , Attribute& attr) const
         {
             // create a local value if Attribute is not unused_type
- typename traits::result_of::value<Attribute>::type val;
+ typename traits::result_of::value<Attribute>::type val =
+ traits::result_of::value<Attribute>::type();
 
             // Repeat while subject parses ok
             while (subject.parse(first, last, context, skipper, val))

Modified: trunk/boost/spirit/home/qi/operator/list.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/operator/list.hpp (original)
+++ trunk/boost/spirit/home/qi/operator/list.hpp 2009-07-28 13:34:13 EDT (Tue, 28 Jul 2009)
@@ -60,7 +60,8 @@
           , Attribute& attr) const
         {
             // create a local value if Attribute is not unused_type
- typename traits::result_of::value<Attribute>::type val;
+ typename traits::result_of::value<Attribute>::type val =
+ traits::result_of::value<Attribute>::type();
 
             if (left.parse(first, last, context, skipper, val))
             {

Modified: trunk/boost/spirit/home/qi/operator/plus.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/operator/plus.hpp (original)
+++ trunk/boost/spirit/home/qi/operator/plus.hpp 2009-07-28 13:34:13 EDT (Tue, 28 Jul 2009)
@@ -58,7 +58,8 @@
           , Attribute& attr) const
         {
             // create a local value if Attribute is not unused_type
- typename traits::result_of::value<Attribute>::type val;
+ typename traits::result_of::value<Attribute>::type val =
+ traits::result_of::value<Attribute>::type();
 
             if (subject.parse(first, last, context, skipper, val))
             {


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