|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r57435 - in trunk: boost/spirit/home/karma/operator libs/spirit/test/karma
From: hartmut.kaiser_at_[hidden]
Date: 2009-11-06 09:40:19
Author: hkaiser
Date: 2009-11-06 09:40:18 EST (Fri, 06 Nov 2009)
New Revision: 57435
URL: http://svn.boost.org/trac/boost/changeset/57435
Log:
Spirit: fixing bug in alternatives taking optionals
Text files modified:
trunk/boost/spirit/home/karma/operator/alternative.hpp | 50 ++-------------------------------------
trunk/libs/spirit/test/karma/alternative.cpp | 12 +++++++++
2 files changed, 15 insertions(+), 47 deletions(-)
Modified: trunk/boost/spirit/home/karma/operator/alternative.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/operator/alternative.hpp (original)
+++ trunk/boost/spirit/home/karma/operator/alternative.hpp 2009-11-06 09:40:18 EST (Fri, 06 Nov 2009)
@@ -101,37 +101,14 @@
alternative(Elements const& elements)
: elements(elements) {}
- // this is the implementation for non-optional and non-empty optional
- // attributes
template <
typename OutputIterator, typename Context, typename Delimiter
, typename Attribute>
- bool generate_dispatch(OutputIterator& sink, Context& ctx
- , Delimiter const& d, Attribute const& attr, mpl::true_) const
- {
- typedef typename
- traits::extract_from_attribute<Attribute>::type attr_type;
- typedef detail::alternative_generate_functor<
- OutputIterator, Context, Delimiter
- , typename remove_const<
- typename remove_reference<attr_type>::type>::type
- > functor;
-
- // f return true if *any* of the parser succeeds
- functor f (sink, ctx, d, traits::extract_from(attr, ctx));
- return fusion::any(elements, f);
- }
-
- // this is the implementation for empty optional attributes, the empty
- // optional is passed through to the embedded generators
- template <
- typename OutputIterator, typename Context, typename Delimiter
- , typename Optional>
- bool generate_optional(OutputIterator& sink, Context& ctx
- , Delimiter const& d, Optional const& attr) const
+ bool generate(OutputIterator& sink, Context& ctx
+ , Delimiter const& d, Attribute const& attr) const
{
typedef detail::alternative_generate_functor<
- OutputIterator, Context, Delimiter, Optional
+ OutputIterator, Context, Delimiter, Attribute
> functor;
// f return true if *any* of the parser succeeds
@@ -139,27 +116,6 @@
return fusion::any(elements, f);
}
- template <
- typename OutputIterator, typename Context, typename Delimiter
- , typename Attribute>
- bool generate_dispatch(OutputIterator& sink, Context& ctx
- , Delimiter const& d, Attribute const& attr, mpl::false_) const
- {
- if (!traits::has_optional_value(attr))
- return generate_optional(sink, ctx, d, attr);
- return generate_dispatch(sink, ctx, d, attr, mpl::true_());
- }
-
- template <
- typename OutputIterator, typename Context, typename Delimiter
- , typename Attribute>
- bool generate(OutputIterator& sink, Context& ctx
- , Delimiter const& d, Attribute const& attr) const
- {
- return generate_dispatch(sink, ctx, d, attr
- , traits::not_is_optional<Attribute>());
- }
-
template <typename Context>
info what(Context& context) const
{
Modified: trunk/libs/spirit/test/karma/alternative.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/alternative.cpp (original)
+++ trunk/libs/spirit/test/karma/alternative.cpp 2009-11-06 09:40:18 EST (Fri, 06 Nov 2009)
@@ -223,6 +223,18 @@
BOOST_TEST(test(">1,2,3,4", '>' << r % ',' | karma::eps, v));
}
+ {
+ typedef spirit_test::output_iterator<char>::type outiter_type;
+ namespace karma = boost::spirit::karma;
+
+ karma::rule<outiter_type, boost::optional<int>()> r = int_;
+ boost::optional<int> o;
+ BOOST_TEST(test("error", r | "error", o));
+
+ o = 10;
+ BOOST_TEST(test("10", r | "error", o));
+ }
+
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