|
Boost-Commit : |
From: hartmut.kaiser_at_[hidden]
Date: 2008-05-07 00:20:06
Author: hkaiser
Date: 2008-05-07 00:20:04 EDT (Wed, 07 May 2008)
New Revision: 45187
URL: http://svn.boost.org/trac/boost/changeset/45187
Log:
Spirit.Karma: Fixed output iterator issue
Text files modified:
trunk/boost/spirit/home/karma/generate.hpp | 114 ++++++++++++++++++++++++++++++++++++++++
trunk/libs/spirit/example/karma/calc2_ast_dump.cpp | 10 +-
trunk/libs/spirit/example/karma/calc2_ast_rpn.cpp | 16 +++--
3 files changed, 128 insertions(+), 12 deletions(-)
Modified: trunk/boost/spirit/home/karma/generate.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/generate.hpp (original)
+++ trunk/boost/spirit/home/karma/generate.hpp 2008-05-07 00:20:04 EDT (Wed, 07 May 2008)
@@ -45,6 +45,27 @@
}
///////////////////////////////////////////////////////////////////////////
+ template <typename OutputIterator, typename Expr>
+ inline bool
+ generate(detail::output_iterator<OutputIterator>& sink, Expr const& xpr)
+ {
+ typedef spirit::traits::is_component<karma::domain, Expr> is_component;
+
+ // report invalid expression error as early as possible
+ BOOST_MPL_ASSERT_MSG(is_component::value,
+ xpr_is_not_convertible_to_a_generator,
+ (OutputIterator, Expr));
+
+ typedef
+ typename result_of::as_component<karma::domain, Expr>::type
+ component;
+ typedef typename component::director director;
+
+ component c = spirit::as_component(karma::domain(), xpr);
+ return director::generate(c, sink, unused, unused, unused);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
template <typename OutputIterator, typename Expr, typename Parameter>
inline bool
generate(OutputIterator target_sink, Expr const& xpr, Parameter const& param)
@@ -69,6 +90,28 @@
}
///////////////////////////////////////////////////////////////////////////
+ template <typename OutputIterator, typename Expr, typename Parameter>
+ inline bool
+ generate(detail::output_iterator<OutputIterator>& sink, Expr const& xpr,
+ Parameter const& param)
+ {
+ typedef spirit::traits::is_component<karma::domain, Expr> is_component;
+
+ // report invalid expression error as early as possible
+ BOOST_MPL_ASSERT_MSG(is_component::value,
+ xpr_is_not_convertible_to_a_generator,
+ (OutputIterator, Expr, Parameter));
+
+ typedef
+ typename result_of::as_component<karma::domain, Expr>::type
+ component;
+ typedef typename component::director director;
+
+ component c = spirit::as_component(karma::domain(), xpr);
+ return director::generate(c, sink, unused, unused, param);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
template <typename OutputIterator, typename Expr, typename Delimiter>
inline bool
generate_delimited(OutputIterator target_sink, Expr const& xpr,
@@ -107,6 +150,41 @@
}
///////////////////////////////////////////////////////////////////////////
+ template <typename OutputIterator, typename Expr, typename Delimiter>
+ inline bool
+ generate_delimited(detail::output_iterator<OutputIterator>& sink,
+ Expr const& xpr, Delimiter const& delimiter)
+ {
+ typedef
+ spirit::traits::is_component<karma::domain, Expr>
+ expr_is_component;
+ typedef
+ spirit::traits::is_component<karma::domain, Delimiter>
+ delimiter_is_component;
+
+ // report invalid expression errors as early as possible
+ BOOST_MPL_ASSERT_MSG(expr_is_component::value,
+ xpr_is_not_convertible_to_a_generator,
+ (OutputIterator, Expr, Delimiter));
+
+ BOOST_MPL_ASSERT_MSG(delimiter_is_component::value,
+ delimiter_is_not_convertible_to_a_generator,
+ (OutputIterator, Expr, Delimiter));
+
+ typedef
+ typename result_of::as_component<karma::domain, Expr>::type
+ component;
+ typedef typename component::director director;
+ typedef
+ typename result_of::as_component<karma::domain, Delimiter>::type
+ delim_component;
+
+ component c = spirit::as_component(karma::domain(), xpr);
+ delim_component d = spirit::as_component(karma::domain(), delimiter);
+ return director::generate(c, sink, unused, d, unused);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
template <typename OutputIterator, typename Expr, typename Parameter,
typename Delimiter>
inline bool
@@ -145,6 +223,42 @@
return director::generate(c, sink, unused, d, param);
}
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename OutputIterator, typename Expr, typename Parameter,
+ typename Delimiter>
+ inline bool
+ generate_delimited(detail::output_iterator<OutputIterator>& sink,
+ Expr const& xpr, Parameter const& param, Delimiter const& delimiter)
+ {
+ typedef
+ spirit::traits::is_component<karma::domain, Expr>
+ expr_is_component;
+ typedef
+ spirit::traits::is_component<karma::domain, Delimiter>
+ delimiter_is_component;
+
+ // report invalid expression errors as early as possible
+ BOOST_MPL_ASSERT_MSG(expr_is_component::value,
+ xpr_is_not_convertible_to_a_generator,
+ (OutputIterator, Expr, Parameter, Delimiter));
+
+ BOOST_MPL_ASSERT_MSG(delimiter_is_component::value,
+ delimiter_is_not_convertible_to_a_generator,
+ (OutputIterator, Expr, Parameter, Delimiter));
+
+ typedef
+ typename result_of::as_component<karma::domain, Expr>::type
+ component;
+ typedef typename component::director director;
+ typedef
+ typename result_of::as_component<karma::domain, Delimiter>::type
+ delim_component;
+
+ component c = spirit::as_component(karma::domain(), xpr);
+ delim_component d = spirit::as_component(karma::domain(), delimiter);
+ return director::generate(c, sink, unused, d, param);
+ }
+
}}}
#endif
Modified: trunk/libs/spirit/example/karma/calc2_ast_dump.cpp
==============================================================================
--- trunk/libs/spirit/example/karma/calc2_ast_dump.cpp (original)
+++ trunk/libs/spirit/example/karma/calc2_ast_dump.cpp 2008-05-07 00:20:04 EDT (Wed, 07 May 2008)
@@ -71,22 +71,22 @@
dump_ast()
{
ast_node %=
- int_ [_1 = _int(_r0)]
- | binary_node [_1 = _bin_op(_r0)]
- | unary_node [_1 = _unary_op(_r0)]
+ int_ [_1 = _int(_val)]
+ | binary_node [_1 = _bin_op(_val)]
+ | unary_node [_1 = _unary_op(_val)]
;
binary_node =
('(' << ast_node << char_ << ast_node << ')')
[
- _1 = _left(_r0), _2 = _op(_r0), _3 = _right(_r0)
+ _1 = _left(_val), _2 = _op(_val), _3 = _right(_val)
]
;
unary_node =
('(' << char_ << ast_node << ')')
[
- _1 = _op(_r0), _2 = _right(_r0)
+ _1 = _op(_val), _2 = _right(_val)
]
;
}
Modified: trunk/libs/spirit/example/karma/calc2_ast_rpn.cpp
==============================================================================
--- trunk/libs/spirit/example/karma/calc2_ast_rpn.cpp (original)
+++ trunk/libs/spirit/example/karma/calc2_ast_rpn.cpp 2008-05-07 00:20:04 EDT (Wed, 07 May 2008)
@@ -72,22 +72,24 @@
ast_rpn()
{
ast_node %=
- int_ [_1 = _int(_r0)]
- | binary_node [_1 = _bin_op(_r0)]
- | unary_node [_1 = _unary_op(_r0)]
+ int_ [_1 = _int(_val)]
+ | binary_node [_1 = _bin_op(_val)]
+ | unary_node [_1 = _unary_op(_val)]
;
binary_node =
(ast_node << ast_node << char_)
[
- _1 = _left(_r0), _2 = _right(_r0), _3 = _op(_r0)
+ _1 = _left(_val), _2 = _right(_val), _3 = _op(_val)
]
;
unary_node =
- verbatim['(' << ast_node << char_ << ')']
- [
- _1 = _right(_r0), _2 = _op(_r0)
+ verbatim [
+ ('(' << ast_node << char_ << ')')
+ [
+ _1 = _right(_val), _2 = _op(_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