|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r72111 - in trunk: boost/spirit/home/support libs/spirit/test/qi
From: hartmut.kaiser_at_[hidden]
Date: 2011-05-22 21:55:33
Author: hkaiser
Date: 2011-05-22 21:55:32 EDT (Sun, 22 May 2011)
New Revision: 72111
URL: http://svn.boost.org/trac/boost/changeset/72111
Log:
Spirit: tweaks to attribute handling
Text files modified:
trunk/boost/spirit/home/support/attributes.hpp | 47 +++++++++++++++++++++++++++++++--------
trunk/libs/spirit/test/qi/pass_container2.cpp | 2
trunk/libs/spirit/test/qi/pass_container3.cpp | 25 ++++++++++++++++++--
3 files changed, 60 insertions(+), 14 deletions(-)
Modified: trunk/boost/spirit/home/support/attributes.hpp
==============================================================================
--- trunk/boost/spirit/home/support/attributes.hpp (original)
+++ trunk/boost/spirit/home/support/attributes.hpp 2011-05-22 21:55:32 EDT (Sun, 22 May 2011)
@@ -112,6 +112,34 @@
// Find out if T can be a weak substitute for Expected attribute
namespace detail
{
+ // A type, which is convertible to the attribute is at the same time
+ // usable as its weak substitute.
+ template <typename T, typename Expected, typename Enable = void>
+ struct is_weak_substitute_impl : is_convertible<T, Expected> {};
+
+// // An exposed attribute is a weak substitute for a supplied container
+// // attribute if it is a weak substitute for its value_type. This is
+// // true as all character parsers exposing compatible with a container
+// // attribute having the corresponding character type as its value_type.
+// template <typename T, typename Expected>
+// struct is_weak_substitute_for_value_type
+// : is_weak_substitute<T, typename container_value<Expected>::type>
+// {};
+//
+// template <typename T, typename Expected>
+// struct is_weak_substitute_impl<T, Expected,
+// typename enable_if<
+// mpl::and_<
+// mpl::not_<is_string<T> >
+// , is_string<Expected>
+// , is_weak_substitute_for_value_type<T, Expected> >
+// >::type>
+// : mpl::true_
+// {};
+
+ // An exposed container attribute is a weak substitute for a supplied
+ // container attribute if and only if their value_types are weak
+ // substitutes.
template <typename T, typename Expected>
struct value_type_is_weak_substitute
: is_weak_substitute<
@@ -119,33 +147,32 @@
, typename container_value<Expected>::type>
{};
- template <typename T, typename Expected, typename Enable = void>
- struct is_weak_substitute_impl : is_convertible<T, Expected> {};
-
template <typename T, typename Expected>
struct is_weak_substitute_impl<T, Expected,
typename enable_if<
mpl::and_<
- is_container<T>,
- is_container<Expected>,
- value_type_is_weak_substitute<T, Expected> >
+ is_container<T>
+ , is_container<Expected>
+ , value_type_is_weak_substitute<T, Expected> >
>::type>
: mpl::true_ {};
+ // Two fusion sequences are weak substitutes if and only if their
+ // elements are pairwise weak substitutes.
template <typename T, typename Expected>
struct is_weak_substitute_impl<T, Expected,
typename enable_if<
mpl::and_<
- fusion::traits::is_sequence<T>,
- fusion::traits::is_sequence<Expected>,
- mpl::equal<T, Expected, is_weak_substitute<mpl::_1, mpl::_2> > >
+ fusion::traits::is_sequence<T>
+ , fusion::traits::is_sequence<Expected>
+ , mpl::equal<T, Expected, is_weak_substitute<mpl::_1, mpl::_2> > >
>::type>
: mpl::true_ {};
// If this is not defined, the main template definition above will return
// true if T is convertible to the first type in a fusion::vector. We
// globally declare any non-Fusion sequence T as not compatible with any
- // Fusion sequence Expected.
+ // Fusion sequence 'Expected'.
template <typename T, typename Expected>
struct is_weak_substitute_impl<T, Expected,
typename enable_if<
Modified: trunk/libs/spirit/test/qi/pass_container2.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/pass_container2.cpp (original)
+++ trunk/libs/spirit/test/qi/pass_container2.cpp 2011-05-22 21:55:32 EDT (Sun, 22 May 2011)
@@ -246,7 +246,7 @@
at_c<0>(v[1]) == 3 && at_c<1>(v[1]) == 4.0);
}
-// doesn't work yet
+// doesn't currently work
// {
// std::vector<std::vector<char> > v2;
// BOOST_TEST(test_attr("ab1cd123", *(alpha >> alpha | +digit), v2) &&
Modified: trunk/libs/spirit/test/qi/pass_container3.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/pass_container3.cpp (original)
+++ trunk/libs/spirit/test/qi/pass_container3.cpp 2011-05-22 21:55:32 EDT (Sun, 22 May 2011)
@@ -5,6 +5,9 @@
// compilation test only
+#include <boost/config/warning_disable.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
#include <string>
#include <vector>
@@ -13,6 +16,10 @@
#include <boost/variant.hpp>
+#include "test.hpp"
+
+using namespace spirit_test;
+
//////////////////////////////////////////////////////////////////////////////
struct ast; // Forward declaration
@@ -38,9 +45,21 @@
{
namespace qi = boost::spirit::qi;
- qi::rule<char const*, ast()> num_expr;
- num_expr = (*(qi::char_ >> num_expr))[ qi::_1 ];
+ {
+ qi::rule<char const*, ast()> num_expr;
+ num_expr = (*(qi::char_ >> num_expr))[ qi::_1 ];
+ }
+
+// doesn't currently work
+// {
+// qi::rule<char const*, std::string()> str = "abc";
+// qi::rule<char const*, std::string()> r =
+// '"' >> *('\\' >> qi::char_ | str) >> "'";
+//
+// std::string s;
+// BOOST_TEST(test_attr("\"abc\\a\"", r, s) && s == "abca");
+// }
- return 0;
+ return boost::report_errors();
}
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