]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright (c) 2001-2011 Hartmut Kaiser |
2 | // | |
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) | |
5 | ||
6 | #if !defined(BOOST_SPIRIT_KARMA_VERBATIM_MAR_02_2007_0303PM) | |
7 | #define BOOST_SPIRIT_KARMA_VERBATIM_MAR_02_2007_0303PM | |
8 | ||
9 | #if defined(_MSC_VER) | |
10 | #pragma once | |
11 | #endif | |
12 | ||
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> | |
25 | ||
26 | namespace boost { namespace spirit | |
27 | { | |
28 | /////////////////////////////////////////////////////////////////////////// | |
29 | // Enablers | |
30 | /////////////////////////////////////////////////////////////////////////// | |
31 | template <> | |
32 | struct use_directive<karma::domain, tag::verbatim> // enables verbatim[] | |
33 | : mpl::true_ {}; | |
34 | ||
35 | }} | |
36 | ||
37 | namespace boost { namespace spirit { namespace karma | |
38 | { | |
39 | #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS | |
40 | using spirit::verbatim; | |
41 | #endif | |
42 | using spirit::verbatim_type; | |
43 | ||
44 | /////////////////////////////////////////////////////////////////////////// | |
45 | // The verbatim generator is used for verbatim[...] directives. | |
46 | /////////////////////////////////////////////////////////////////////////// | |
47 | template <typename Subject> | |
48 | struct verbatim_generator : unary_generator<verbatim_generator<Subject> > | |
49 | { | |
50 | typedef Subject subject_type; | |
51 | typedef typename subject_type::properties properties; | |
52 | ||
53 | template <typename Context, typename Iterator> | |
54 | struct attribute | |
55 | : traits::attribute_of<subject_type, Context, Iterator> | |
56 | {}; | |
57 | ||
58 | verbatim_generator(Subject const& subject) | |
59 | : subject(subject) {} | |
60 | ||
61 | template <typename OutputIterator, typename Context, typename Delimiter | |
62 | , typename Attribute> | |
63 | bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d | |
64 | , Attribute const& attr) const | |
65 | { | |
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; | |
70 | ||
71 | return subject.generate(sink, ctx, unused_delimiter(d), attr) && | |
72 | karma::delimit_out(sink, d); // always do post-delimiting | |
73 | } | |
74 | ||
75 | template <typename Context> | |
76 | info what(Context& context) const | |
77 | { | |
78 | return info("verbatim", subject.what(context)); | |
79 | } | |
80 | ||
81 | Subject subject; | |
82 | }; | |
83 | ||
84 | /////////////////////////////////////////////////////////////////////////// | |
85 | // Generator generators: make_xxx function (objects) | |
86 | /////////////////////////////////////////////////////////////////////////// | |
87 | template <typename Subject, typename Modifiers> | |
88 | struct make_directive<tag::verbatim, Subject, Modifiers> | |
89 | { | |
90 | typedef verbatim_generator<Subject> result_type; | |
91 | result_type operator()(unused_type, Subject const& subject, unused_type) const | |
92 | { | |
93 | return result_type(subject); | |
94 | } | |
95 | }; | |
96 | ||
97 | }}} | |
98 | ||
99 | namespace boost { namespace spirit { namespace traits | |
100 | { | |
101 | /////////////////////////////////////////////////////////////////////////// | |
102 | template <typename Subject> | |
103 | struct has_semantic_action<karma::verbatim_generator<Subject> > | |
104 | : unary_has_semantic_action<Subject> {}; | |
105 | ||
106 | /////////////////////////////////////////////////////////////////////////// | |
107 | template <typename Subject, typename Attribute, typename Context | |
108 | , typename Iterator> | |
109 | struct handles_container<karma::verbatim_generator<Subject>, Attribute | |
110 | , Context, Iterator> | |
111 | : unary_handles_container<Subject, Attribute, Context, Iterator> {}; | |
112 | }}} | |
113 | ||
114 | #endif |