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_VERBATIM_MAR_02_2007_0303PM)
7 #define BOOST_SPIRIT_KARMA_VERBATIM_MAR_02_2007_0303PM
13 #include <boost/spirit/home/karma/meta_compiler.hpp>
14 #include <boost/spirit/home/karma/generator.hpp>
15 #include <boost/spirit/home/karma/domain.hpp>
16 #include <boost/spirit/home/karma/detail/unused_delimiter.hpp>
17 #include <boost/spirit/home/karma/delimit_out.hpp>
18 #include <boost/spirit/home/karma/auxiliary/lazy.hpp>
19 #include <boost/spirit/home/support/unused.hpp>
20 #include <boost/spirit/home/support/common_terminals.hpp>
21 #include <boost/spirit/home/support/has_semantic_action.hpp>
22 #include <boost/spirit/home/support/handles_container.hpp>
23 #include <boost/spirit/home/karma/detail/attributes.hpp>
24 #include <boost/spirit/home/support/info.hpp>
26 namespace boost { namespace spirit
28 ///////////////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////////////////////////////////////////
32 struct use_directive<karma::domain, tag::verbatim> // enables verbatim[]
37 namespace boost { namespace spirit { namespace karma
39 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
40 using spirit::verbatim;
42 using spirit::verbatim_type;
44 ///////////////////////////////////////////////////////////////////////////
45 // The verbatim generator is used for verbatim[...] directives.
46 ///////////////////////////////////////////////////////////////////////////
47 template <typename Subject>
48 struct verbatim_generator : unary_generator<verbatim_generator<Subject> >
50 typedef Subject subject_type;
51 typedef typename subject_type::properties properties;
53 template <typename Context, typename Iterator>
55 : traits::attribute_of<subject_type, Context, Iterator>
58 verbatim_generator(Subject const& subject)
61 template <typename OutputIterator, typename Context, typename Delimiter
63 bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d
64 , Attribute const& attr) const
66 // the verbatim generator simply dispatches to the embedded
67 // generator while supplying unused_delimiter as the new delimiter
68 // to avoid delimiting down the generator stream
69 typedef detail::unused_delimiter<Delimiter> unused_delimiter;
71 return subject.generate(sink, ctx, unused_delimiter(d), attr) &&
72 karma::delimit_out(sink, d); // always do post-delimiting
75 template <typename Context>
76 info what(Context& context) const
78 return info("verbatim", subject.what(context));
84 ///////////////////////////////////////////////////////////////////////////
85 // Generator generators: make_xxx function (objects)
86 ///////////////////////////////////////////////////////////////////////////
87 template <typename Subject, typename Modifiers>
88 struct make_directive<tag::verbatim, Subject, Modifiers>
90 typedef verbatim_generator<Subject> result_type;
91 result_type operator()(unused_type, Subject const& subject, unused_type) const
93 return result_type(subject);
99 namespace boost { namespace spirit { namespace traits
101 ///////////////////////////////////////////////////////////////////////////
102 template <typename Subject>
103 struct has_semantic_action<karma::verbatim_generator<Subject> >
104 : unary_has_semantic_action<Subject> {};
106 ///////////////////////////////////////////////////////////////////////////
107 template <typename Subject, typename Attribute, typename Context
109 struct handles_container<karma::verbatim_generator<Subject>, Attribute
111 : unary_handles_container<Subject, Attribute, Context, Iterator> {};