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_REPOSITORY_KARMA_CONFIX_AUG_19_2008_1041AM)
7 #define BOOST_SPIRIT_REPOSITORY_KARMA_CONFIX_AUG_19_2008_1041AM
13 #include <boost/spirit/home/support/common_terminals.hpp>
14 #include <boost/spirit/home/support/info.hpp>
15 #include <boost/spirit/home/support/unused.hpp>
16 #include <boost/spirit/home/karma/detail/attributes.hpp>
17 #include <boost/spirit/home/karma/domain.hpp>
18 #include <boost/spirit/home/karma/meta_compiler.hpp>
20 #include <boost/spirit/repository/home/support/confix.hpp>
22 #include <boost/fusion/include/vector.hpp>
23 #include <boost/mpl/or.hpp>
25 ///////////////////////////////////////////////////////////////////////////////
26 namespace boost { namespace spirit
28 ///////////////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////////////////////////////////////////
32 // enables confix(..., ...)[]
33 template <typename Prefix, typename Suffix>
34 struct use_directive<karma::domain
35 , terminal_ex<repository::tag::confix, fusion::vector2<Prefix, Suffix> > >
38 // enables *lazy* confix(..., ...)[g]
40 struct use_lazy_directive<karma::domain, repository::tag::confix, 2>
45 ///////////////////////////////////////////////////////////////////////////////
46 namespace boost { namespace spirit { namespace repository { namespace karma
48 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
49 using repository::confix;
51 using repository::confix_type;
53 ///////////////////////////////////////////////////////////////////////////
54 template <typename Subject, typename Prefix, typename Suffix>
55 struct confix_generator
56 : spirit::karma::primitive_generator<confix_generator<Subject, Prefix, Suffix> >
58 typedef Subject subject_type;
60 template <typename Context, typename Iterator>
62 : traits::attribute_of<subject_type, Context, Iterator>
65 confix_generator(Subject const& subject, Prefix const& prefix
66 , Suffix const& suffix)
67 : subject(subject), prefix(prefix), suffix(suffix) {}
69 ///////////////////////////////////////////////////////////////////////
70 template <typename OutputIterator, typename Context, typename Delimiter
72 bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d
73 , Attribute const& attr) const
75 // generate the prefix, the embedded item and the suffix
76 return prefix.generate(sink, ctx, d, unused) &&
77 subject.generate(sink, ctx, d, attr) &&
78 suffix.generate(sink, ctx, d, unused);
81 template <typename Context>
82 info what(Context const& ctx) const
84 return info("confix", subject.what(ctx));
94 ///////////////////////////////////////////////////////////////////////////////
95 namespace boost { namespace spirit { namespace karma
97 ///////////////////////////////////////////////////////////////////////////
98 // Generator generators: make_xxx function (objects)
99 ///////////////////////////////////////////////////////////////////////////
101 // creates confix(..., ...)[] directive generator
102 template <typename Prefix, typename Suffix, typename Subject
103 , typename Modifiers>
104 struct make_directive<
105 terminal_ex<repository::tag::confix, fusion::vector2<Prefix, Suffix> >
106 , Subject, Modifiers>
109 result_of::compile<karma::domain, Prefix, Modifiers>::type
112 result_of::compile<karma::domain, Suffix, Modifiers>::type
115 typedef repository::karma::confix_generator<
116 Subject, prefix_type, suffix_type> result_type;
118 template <typename Terminal>
119 result_type operator()(Terminal const& term, Subject const& subject
120 , Modifiers const& modifiers) const
122 return result_type(subject
123 , compile<karma::domain>(fusion::at_c<0>(term.args), modifiers)
124 , compile<karma::domain>(fusion::at_c<1>(term.args), modifiers));
130 namespace boost { namespace spirit { namespace traits
132 template <typename Subject, typename Prefix, typename Suffix>
133 struct has_semantic_action<
134 repository::karma::confix_generator<Subject, Prefix, Suffix> >
136 has_semantic_action<Subject>
137 , has_semantic_action<Prefix>
138 , has_semantic_action<Suffix>