File indexing completed on 2025-01-19 09:47:36
0001
0002
0003
0004
0005
0006 #if !defined(BOOST_SPIRIT_KARMA_DELIMIT_MAR_02_2007_0217PM)
0007 #define BOOST_SPIRIT_KARMA_DELIMIT_MAR_02_2007_0217PM
0008
0009 #if defined(_MSC_VER)
0010 #pragma once
0011 #endif
0012
0013 #include <boost/spirit/home/karma/meta_compiler.hpp>
0014 #include <boost/spirit/home/karma/generator.hpp>
0015 #include <boost/spirit/home/karma/domain.hpp>
0016 #include <boost/spirit/home/karma/detail/unused_delimiter.hpp>
0017 #include <boost/spirit/home/karma/delimit_out.hpp>
0018 #include <boost/spirit/home/karma/auxiliary/lazy.hpp>
0019 #include <boost/spirit/home/karma/char/char.hpp>
0020 #include <boost/spirit/home/support/unused.hpp>
0021 #include <boost/spirit/home/support/common_terminals.hpp>
0022 #include <boost/spirit/home/support/has_semantic_action.hpp>
0023 #include <boost/spirit/home/support/handles_container.hpp>
0024 #include <boost/spirit/home/karma/detail/attributes.hpp>
0025 #include <boost/spirit/home/support/info.hpp>
0026 #include <boost/fusion/include/at.hpp>
0027 #include <boost/fusion/include/vector.hpp>
0028
0029 namespace boost { namespace spirit
0030 {
0031
0032
0033
0034 template <>
0035 struct use_directive<karma::domain, tag::delimit>
0036 : mpl::true_ {};
0037
0038
0039 template <typename T>
0040 struct use_directive<karma::domain
0041 , terminal_ex<tag::delimit, fusion::vector1<T> > >
0042 : boost::spirit::traits::matches<karma::domain, T> {};
0043
0044
0045 template <>
0046 struct use_lazy_directive<karma::domain, tag::delimit, 1>
0047 : mpl::true_ {};
0048
0049 }}
0050
0051 namespace boost { namespace spirit { namespace karma
0052 {
0053 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
0054 using spirit::delimit;
0055 #endif
0056 using spirit::delimit_type;
0057
0058
0059
0060
0061 template <typename Subject>
0062 struct redelimit_generator : unary_generator<redelimit_generator<Subject> >
0063 {
0064 typedef Subject subject_type;
0065
0066 typedef typename subject_type::properties properties;
0067
0068 template <typename Context, typename Iterator>
0069 struct attribute
0070 : traits::attribute_of<subject_type, Context, Iterator>
0071 {};
0072
0073 redelimit_generator(Subject const& subject)
0074 : subject(subject) {}
0075
0076 template <typename OutputIterator, typename Context, typename Delimiter
0077 , typename Attribute>
0078 bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d
0079 , Attribute const& attr) const
0080 {
0081
0082
0083
0084
0085
0086 return subject.generate(sink, ctx
0087 , detail::get_delimiter(d, compile<karma::domain>(' ')), attr);
0088 }
0089
0090 template <typename Context>
0091 info what(Context& context) const
0092 {
0093 return info("delimit", subject.what(context));
0094 }
0095
0096 Subject subject;
0097 };
0098
0099
0100
0101
0102 template <typename Subject, typename Delimiter>
0103 struct delimit_generator
0104 : unary_generator<delimit_generator<Subject, Delimiter> >
0105 {
0106 typedef Subject subject_type;
0107 typedef Delimiter delimiter_type;
0108
0109 typedef typename subject_type::properties properties;
0110
0111 template <typename Context, typename Iterator>
0112 struct attribute
0113 : traits::attribute_of<subject_type, Context, Iterator>
0114 {};
0115
0116 delimit_generator(Subject const& subject, Delimiter const& delimiter)
0117 : subject(subject), delimiter(delimiter) {}
0118
0119 template <typename OutputIterator, typename Context
0120 , typename Delimiter_, typename Attribute>
0121 bool generate(OutputIterator& sink, Context& ctx, Delimiter_ const&
0122 , Attribute const& attr) const
0123 {
0124
0125
0126
0127 return subject.generate(sink, ctx, delimiter, attr);
0128 }
0129
0130 template <typename Context>
0131 info what(Context& context) const
0132 {
0133 return info("delimit", subject.what(context));
0134 }
0135
0136 Subject subject;
0137 Delimiter delimiter;
0138 };
0139
0140
0141
0142
0143 template <typename Subject, typename Modifiers>
0144 struct make_directive<tag::delimit, Subject, Modifiers>
0145 {
0146 typedef redelimit_generator<Subject> result_type;
0147 result_type operator()(unused_type, Subject const& subject
0148 , unused_type) const
0149 {
0150 return result_type(subject);
0151 }
0152 };
0153
0154 template <typename Delimiter, typename Subject, typename Modifiers>
0155 struct make_directive<
0156 terminal_ex<tag::delimit, fusion::vector1<Delimiter> >
0157 , Subject, Modifiers>
0158 {
0159 typedef typename
0160 result_of::compile<karma::domain, Delimiter, Modifiers>::type
0161 delimiter_type;
0162
0163 typedef delimit_generator<Subject, delimiter_type> result_type;
0164
0165 template <typename Terminal>
0166 result_type operator()(Terminal const& term, Subject const& subject
0167 , unused_type) const
0168 {
0169 return result_type(subject
0170 , compile<karma::domain>(fusion::at_c<0>(term.args)));
0171 }
0172 };
0173
0174 }}}
0175
0176 namespace boost { namespace spirit { namespace traits
0177 {
0178
0179 template <typename Subject>
0180 struct has_semantic_action<karma::redelimit_generator<Subject> >
0181 : unary_has_semantic_action<Subject> {};
0182
0183 template <typename Subject, typename Delimiter>
0184 struct has_semantic_action<karma::delimit_generator<Subject, Delimiter> >
0185 : unary_has_semantic_action<Subject> {};
0186
0187
0188 template <typename Subject, typename Attribute
0189 , typename Context, typename Iterator>
0190 struct handles_container<karma::redelimit_generator<Subject>, Attribute
0191 , Context, Iterator>
0192 : unary_handles_container<Subject, Attribute, Context, Iterator> {};
0193
0194 template <typename Subject, typename Delimiter, typename Attribute
0195 , typename Context, typename Iterator>
0196 struct handles_container<karma::delimit_generator<Subject, Delimiter>
0197 , Attribute, Context, Iterator>
0198 : unary_handles_container<Subject, Attribute, Context, Iterator> {};
0199 }}}
0200
0201 #endif