1 // Copyright (c) 2001-2011 Hartmut Kaiser
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #if !defined(BOOST_SPIRIT_KARMA_EPS_APRIL_21_2007_0246PM)
7 #define BOOST_SPIRIT_KARMA_EPS_APRIL_21_2007_0246PM
13 #include <boost/spirit/home/support/common_terminals.hpp>
14 #include <boost/spirit/home/support/info.hpp>
15 #include <boost/spirit/home/karma/domain.hpp>
16 #include <boost/spirit/home/karma/meta_compiler.hpp>
17 #include <boost/spirit/home/karma/delimit_out.hpp>
18 #include <boost/spirit/home/support/unused.hpp>
19 #include <boost/fusion/include/at.hpp>
21 namespace boost { namespace spirit
23 ///////////////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////////////
29 struct use_terminal<karma::domain, tag::eps>
32 // enables eps(bool-condition)
33 template <typename A0>
34 struct use_terminal<karma::domain
35 , terminal_ex<tag::eps, fusion::vector1<A0> > >
36 : is_convertible<A0, bool> {};
38 // enables lazy eps(f)
40 struct use_lazy_terminal<karma::domain, tag::eps, 1>
45 ///////////////////////////////////////////////////////////////////////////////
46 namespace boost { namespace spirit { namespace karma
48 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
49 using boost::spirit::eps;
51 using boost::spirit::eps_type;
53 struct eps_generator : primitive_generator<eps_generator>
55 template <typename Context, typename Unused>
58 typedef unused_type type;
62 typename OutputIterator, typename Context, typename Delimiter
64 static bool generate(OutputIterator& sink, Context&, Delimiter const& d
65 , Attribute const& /*attr*/)
67 return karma::delimit_out(sink, d); // always do post-delimiting
70 template <typename Context>
71 info what(Context const& /*context*/) const
77 struct semantic_predicate : primitive_generator<semantic_predicate>
79 template <typename Context, typename Unused>
82 typedef unused_type type;
85 semantic_predicate(bool predicate)
86 : predicate_(predicate)
90 typename OutputIterator, typename Context, typename Delimiter
92 bool generate(OutputIterator& sink, Context&, Delimiter const& d
93 , Attribute const& /*attr*/) const
95 // only do post-delimiting when predicate is true
96 return predicate_ && karma::delimit_out(sink, d);
99 template <typename Context>
100 info what(Context const& /*context*/) const
102 return info("semantic-predicate");
108 ///////////////////////////////////////////////////////////////////////////
109 // Generator generators: make_xxx function (objects)
110 ///////////////////////////////////////////////////////////////////////////
111 template <typename Modifiers>
112 struct make_primitive<tag::eps, Modifiers>
114 typedef eps_generator result_type;
115 result_type operator()(unused_type, unused_type) const
117 return result_type();
121 template <typename Modifiers, typename A0>
122 struct make_primitive<
123 terminal_ex<tag::eps, fusion::vector1<A0> >
126 typedef semantic_predicate result_type;
128 template <typename Terminal>
129 result_type operator()(Terminal const& term, unused_type) const
131 return result_type(fusion::at_c<0>(term.args));