|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r71377 - in trunk/boost/spirit/home: karma/nonterminal qi/nonterminal qi/numeric
From: joel_at_[hidden]
Date: 2011-04-19 01:11:05
Author: djowel
Date: 2011-04-19 01:11:04 EDT (Tue, 19 Apr 2011)
New Revision: 71377
URL: http://svn.boost.org/trac/boost/changeset/71377
Log:
Better static error handling for rules
Text files modified:
trunk/boost/spirit/home/karma/nonterminal/rule.hpp | 40 +++++++++++++++++++---------------------
trunk/boost/spirit/home/qi/nonterminal/rule.hpp | 36 +++++++++++++++++-------------------
trunk/boost/spirit/home/qi/numeric/numeric_utils.hpp | 1 +
trunk/boost/spirit/home/qi/numeric/uint.hpp | 5 +++--
4 files changed, 40 insertions(+), 42 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 2011-04-19 01:11:04 EDT (Tue, 19 Apr 2011)
@@ -175,20 +175,30 @@
{
}
- template <typename Expr>
- rule (Expr const& expr, std::string const& name_ = "unnamed-rule")
- : base_type(terminal::make(reference_(*this)))
- , name_(name_)
+ template <typename Auto, typename Expr>
+ static void define(rule& lhs, Expr const& expr, mpl::false_)
{
// 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_>(
+ template <typename Auto, typename Expr>
+ static void define(rule& lhs, Expr const& expr, mpl::true_)
+ {
+ lhs.f = detail::bind_generator<Auto>(
compile<karma::domain>(expr, encoding_modifier_type()));
}
+ template <typename Expr>
+ rule (Expr const& expr, std::string const& name_ = "unnamed-rule")
+ : base_type(terminal::make(reference_(*this)))
+ , name_(name_)
+ {
+ define<mpl::false_>(*this, expr, traits::matches<karma::domain, Expr>());
+ }
+
rule& operator=(rule const& rhs)
{
// The following assertion fires when you try to initialize a rule
@@ -215,13 +225,7 @@
template <typename Expr>
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.
- BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
-
- f = detail::bind_generator<mpl::false_>(
- compile<karma::domain>(expr, encoding_modifier_type()));
+ define<mpl::false_>(*this, expr, traits::matches<karma::domain, Expr>());
return *this;
}
@@ -231,13 +235,7 @@
template <typename Expr>
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.
- BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
-
- r.f = detail::bind_generator<mpl::true_>(
- compile<karma::domain>(expr, encoding_modifier_type()));
+ define<mpl::true_>(r, expr, traits::matches<karma::domain, Expr>());
return r;
}
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 2011-04-19 01:11:04 EDT (Tue, 19 Apr 2011)
@@ -167,20 +167,30 @@
{
}
- template <typename Expr>
- rule(Expr const& expr, std::string const& name_ = "unnamed-rule")
- : base_type(terminal::make(reference_(*this)))
- , name_(name_)
+ template <typename Auto, typename Expr>
+ static void define(rule& lhs, Expr const& expr, mpl::false_)
{
// 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::false_>(
+ template <typename Auto, typename Expr>
+ static void define(rule& lhs, Expr const& expr, mpl::true_)
+ {
+ lhs.f = detail::bind_parser<Auto>(
compile<qi::domain>(expr, encoding_modifier_type()));
}
+ template <typename Expr>
+ rule(Expr const& expr, std::string const& name_ = "unnamed-rule")
+ : base_type(terminal::make(reference_(*this)))
+ , name_(name_)
+ {
+ define<mpl::false_>(*this, expr, traits::matches<qi::domain, Expr>());
+ }
+
rule& operator=(rule const& rhs)
{
// The following assertion fires when you try to initialize a rule
@@ -207,13 +217,7 @@
template <typename Expr>
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 qi expression.
- BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
-
- f = detail::bind_parser<mpl::false_>(
- compile<qi::domain>(expr, encoding_modifier_type()));
+ define<mpl::false_>(*this, expr, traits::matches<qi::domain, Expr>());
return *this;
}
@@ -223,13 +227,7 @@
template <typename Expr>
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 qi expression.
- BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
-
- r.f = detail::bind_parser<mpl::true_>(
- compile<qi::domain>(expr, encoding_modifier_type()));
+ define<mpl::true_>(r, expr, traits::matches<qi::domain, Expr>());
return r;
}
Modified: trunk/boost/spirit/home/qi/numeric/numeric_utils.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/numeric/numeric_utils.hpp (original)
+++ trunk/boost/spirit/home/qi/numeric/numeric_utils.hpp 2011-04-19 01:11:04 EDT (Tue, 19 Apr 2011)
@@ -1,5 +1,6 @@
/*=============================================================================
Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2011 Jan Frederick Eick
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Modified: trunk/boost/spirit/home/qi/numeric/uint.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/numeric/uint.hpp (original)
+++ trunk/boost/spirit/home/qi/numeric/uint.hpp 2011-04-19 01:11:04 EDT (Tue, 19 Apr 2011)
@@ -1,6 +1,7 @@
/*=============================================================================
Copyright (c) 2001-2011 Joel de Guzman
- Copyright (c) 2011 Bryce Lelbach
+ Copyright (c) 2011 Bryce Lelbach
+ Copyright (c) 2011 Jan Frederick Eick
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -29,7 +30,7 @@
{
template <typename T, unsigned Radix, unsigned MinDigits
, int MaxDigits>
- struct uint_parser
+ struct uint_parser
{
BOOST_SPIRIT_IS_TAG()
};
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