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 using repository::confix_type
;
49 using repository::confix
;
51 ///////////////////////////////////////////////////////////////////////////
52 template <typename Subject
, typename Prefix
, typename Suffix
>
53 struct confix_generator
54 : spirit::karma::primitive_generator
<confix_generator
<Subject
, Prefix
, Suffix
> >
56 typedef Subject subject_type
;
58 template <typename Context
, typename Iterator
>
60 : traits::attribute_of
<subject_type
, Context
, Iterator
>
63 confix_generator(Subject
const& subject
, Prefix
const& prefix
64 , Suffix
const& suffix
)
65 : subject(subject
), prefix(prefix
), suffix(suffix
) {}
67 ///////////////////////////////////////////////////////////////////////
68 template <typename OutputIterator
, typename Context
, typename Delimiter
70 bool generate(OutputIterator
& sink
, Context
& ctx
, Delimiter
const& d
71 , Attribute
const& attr
) const
73 // generate the prefix, the embedded item and the suffix
74 return prefix
.generate(sink
, ctx
, d
, unused
) &&
75 subject
.generate(sink
, ctx
, d
, attr
) &&
76 suffix
.generate(sink
, ctx
, d
, unused
);
79 template <typename Context
>
80 info
what(Context
const& ctx
) const
82 return info("confix", subject
.what(ctx
));
92 ///////////////////////////////////////////////////////////////////////////////
93 namespace boost
{ namespace spirit
{ namespace karma
95 ///////////////////////////////////////////////////////////////////////////
96 // Generator generators: make_xxx function (objects)
97 ///////////////////////////////////////////////////////////////////////////
99 // creates confix(..., ...)[] directive generator
100 template <typename Prefix
, typename Suffix
, typename Subject
101 , typename Modifiers
>
102 struct make_directive
<
103 terminal_ex
<repository::tag::confix
, fusion::vector2
<Prefix
, Suffix
> >
104 , Subject
, Modifiers
>
107 result_of::compile
<karma::domain
, Prefix
, Modifiers
>::type
110 result_of::compile
<karma::domain
, Suffix
, Modifiers
>::type
113 typedef repository::karma::confix_generator
<
114 Subject
, prefix_type
, suffix_type
> result_type
;
116 template <typename Terminal
>
117 result_type
operator()(Terminal
const& term
, Subject
const& subject
118 , Modifiers
const& modifiers
) const
120 return result_type(subject
121 , compile
<karma::domain
>(fusion::at_c
<0>(term
.args
), modifiers
)
122 , compile
<karma::domain
>(fusion::at_c
<1>(term
.args
), modifiers
));
128 namespace boost
{ namespace spirit
{ namespace traits
130 template <typename Subject
, typename Prefix
, typename Suffix
>
131 struct has_semantic_action
<
132 repository::karma::confix_generator
<Subject
, Prefix
, Suffix
> >
134 has_semantic_action
<Subject
>
135 , has_semantic_action
<Prefix
>
136 , has_semantic_action
<Suffix
>