Chris@16
|
1 // Copyright (c) 2001-2011 Hartmut Kaiser
|
Chris@16
|
2 // Copyright (c) 2010 Bryce Lelbach
|
Chris@16
|
3 //
|
Chris@16
|
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6
|
Chris@16
|
7 #if !defined(BOOST_SPIRIT_KARMA_CHAR_FEB_21_2007_0543PM)
|
Chris@16
|
8 #define BOOST_SPIRIT_KARMA_CHAR_FEB_21_2007_0543PM
|
Chris@16
|
9
|
Chris@16
|
10 #if defined(_MSC_VER)
|
Chris@16
|
11 #pragma once
|
Chris@16
|
12 #endif
|
Chris@16
|
13
|
Chris@16
|
14 #include <boost/spirit/home/support/common_terminals.hpp>
|
Chris@16
|
15 #include <boost/spirit/home/support/string_traits.hpp>
|
Chris@16
|
16 #include <boost/spirit/home/support/info.hpp>
|
Chris@16
|
17 #include <boost/spirit/home/support/char_class.hpp>
|
Chris@16
|
18 #include <boost/spirit/home/support/detail/get_encoding.hpp>
|
Chris@16
|
19 #include <boost/spirit/home/support/char_set/basic_chset.hpp>
|
Chris@16
|
20 #include <boost/spirit/home/karma/domain.hpp>
|
Chris@16
|
21 #include <boost/spirit/home/karma/meta_compiler.hpp>
|
Chris@16
|
22 #include <boost/spirit/home/karma/delimit_out.hpp>
|
Chris@16
|
23 #include <boost/spirit/home/karma/char/char_generator.hpp>
|
Chris@16
|
24 #include <boost/spirit/home/karma/auxiliary/lazy.hpp>
|
Chris@16
|
25 #include <boost/spirit/home/karma/detail/get_casetag.hpp>
|
Chris@16
|
26 #include <boost/spirit/home/karma/detail/generate_to.hpp>
|
Chris@16
|
27 #include <boost/spirit/home/karma/detail/enable_lit.hpp>
|
Chris@16
|
28 #include <boost/fusion/include/at.hpp>
|
Chris@16
|
29 #include <boost/fusion/include/vector.hpp>
|
Chris@16
|
30 #include <boost/fusion/include/cons.hpp>
|
Chris@16
|
31 #include <boost/mpl/if.hpp>
|
Chris@16
|
32 #include <boost/mpl/assert.hpp>
|
Chris@16
|
33 #include <boost/mpl/bool.hpp>
|
Chris@16
|
34 #include <boost/utility/enable_if.hpp>
|
Chris@16
|
35 #include <string>
|
Chris@16
|
36
|
Chris@16
|
37 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
38 namespace boost { namespace spirit
|
Chris@16
|
39 {
|
Chris@16
|
40 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
41 // Enablers
|
Chris@16
|
42 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
43 template <typename CharEncoding>
|
Chris@16
|
44 struct use_terminal<karma::domain
|
Chris@16
|
45 , tag::char_code<tag::char_, CharEncoding> // enables char_
|
Chris@16
|
46 > : mpl::true_ {};
|
Chris@16
|
47
|
Chris@16
|
48 template <typename CharEncoding, typename A0>
|
Chris@16
|
49 struct use_terminal<karma::domain
|
Chris@16
|
50 , terminal_ex<
|
Chris@16
|
51 tag::char_code<tag::char_, CharEncoding> // enables char_('x'), char_("x")
|
Chris@16
|
52 , fusion::vector1<A0>
|
Chris@16
|
53 >
|
Chris@16
|
54 > : mpl::true_ {};
|
Chris@16
|
55
|
Chris@16
|
56 template <typename A0>
|
Chris@16
|
57 struct use_terminal<karma::domain
|
Chris@16
|
58 , terminal_ex<tag::lit, fusion::vector1<A0> > // enables lit('x')
|
Chris@16
|
59 , typename enable_if<traits::is_char<A0> >::type>
|
Chris@16
|
60 : mpl::true_ {};
|
Chris@16
|
61
|
Chris@16
|
62 template <typename CharEncoding, typename A0, typename A1>
|
Chris@16
|
63 struct use_terminal<karma::domain
|
Chris@16
|
64 , terminal_ex<
|
Chris@16
|
65 tag::char_code<tag::char_, CharEncoding> // enables char_('a','z')
|
Chris@16
|
66 , fusion::vector2<A0, A1>
|
Chris@16
|
67 >
|
Chris@16
|
68 > : mpl::true_ {};
|
Chris@16
|
69
|
Chris@16
|
70 template <typename CharEncoding> // enables *lazy* char_('x'), char_("x")
|
Chris@16
|
71 struct use_lazy_terminal<
|
Chris@16
|
72 karma::domain
|
Chris@16
|
73 , tag::char_code<tag::char_, CharEncoding>
|
Chris@16
|
74 , 1 // arity
|
Chris@16
|
75 > : mpl::true_ {};
|
Chris@16
|
76
|
Chris@16
|
77 template <>
|
Chris@16
|
78 struct use_terminal<karma::domain, char> // enables 'x'
|
Chris@16
|
79 : mpl::true_ {};
|
Chris@16
|
80
|
Chris@16
|
81 template <>
|
Chris@16
|
82 struct use_terminal<karma::domain, char[2]> // enables "x"
|
Chris@16
|
83 : mpl::true_ {};
|
Chris@16
|
84
|
Chris@16
|
85 template <>
|
Chris@16
|
86 struct use_terminal<karma::domain, wchar_t> // enables L'x'
|
Chris@16
|
87 : mpl::true_ {};
|
Chris@16
|
88
|
Chris@16
|
89 template <>
|
Chris@16
|
90 struct use_terminal<karma::domain, wchar_t[2]> // enables L"x"
|
Chris@16
|
91 : mpl::true_ {};
|
Chris@16
|
92 }}
|
Chris@16
|
93
|
Chris@16
|
94 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
95 namespace boost { namespace spirit { namespace karma
|
Chris@16
|
96 {
|
Chris@16
|
97 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
|
Chris@16
|
98 using spirit::lit; // lit('x') is equivalent to 'x'
|
Chris@16
|
99 #endif
|
Chris@16
|
100 using spirit::lit_type;
|
Chris@16
|
101
|
Chris@16
|
102 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
103 //
|
Chris@16
|
104 // any_char
|
Chris@16
|
105 // generates a single character from the associated attribute
|
Chris@16
|
106 //
|
Chris@16
|
107 // Note: this generator has to have an associated attribute
|
Chris@16
|
108 //
|
Chris@16
|
109 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
110 template <typename CharEncoding, typename Tag>
|
Chris@16
|
111 struct any_char
|
Chris@16
|
112 : char_generator<any_char<CharEncoding, Tag>, CharEncoding, Tag>
|
Chris@16
|
113 {
|
Chris@16
|
114 typedef typename CharEncoding::char_type char_type;
|
Chris@16
|
115 typedef CharEncoding char_encoding;
|
Chris@16
|
116
|
Chris@16
|
117 template <typename Context, typename Unused>
|
Chris@16
|
118 struct attribute
|
Chris@16
|
119 {
|
Chris@16
|
120 typedef char_type type;
|
Chris@16
|
121 };
|
Chris@16
|
122
|
Chris@16
|
123 // any_char has an attached parameter
|
Chris@16
|
124 template <typename Attribute, typename CharParam, typename Context>
|
Chris@16
|
125 bool test(Attribute const& attr, CharParam& ch, Context&) const
|
Chris@16
|
126 {
|
Chris@16
|
127 ch = CharParam(attr);
|
Chris@16
|
128 return true;
|
Chris@16
|
129 }
|
Chris@16
|
130
|
Chris@16
|
131 // any_char has no attribute attached, it needs to have been
|
Chris@16
|
132 // initialized from a direct literal
|
Chris@16
|
133 template <typename CharParam, typename Context>
|
Chris@16
|
134 bool test(unused_type, CharParam&, Context&) const
|
Chris@16
|
135 {
|
Chris@16
|
136 // It is not possible (doesn't make sense) to use char_ without
|
Chris@16
|
137 // providing any attribute, as the generator doesn't 'know' what
|
Chris@16
|
138 // character to output. The following assertion fires if this
|
Chris@16
|
139 // situation is detected in your code.
|
Chris@16
|
140 BOOST_SPIRIT_ASSERT_FAIL(CharParam, char_not_usable_without_attribute, ());
|
Chris@16
|
141 return false;
|
Chris@16
|
142 }
|
Chris@16
|
143
|
Chris@16
|
144 template <typename Context>
|
Chris@16
|
145 static info what(Context const& /*context*/)
|
Chris@16
|
146 {
|
Chris@16
|
147 return info("any-char");
|
Chris@16
|
148 }
|
Chris@16
|
149 };
|
Chris@16
|
150
|
Chris@16
|
151 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
152 //
|
Chris@16
|
153 // literal_char
|
Chris@16
|
154 // generates a single character given by a literal it was initialized
|
Chris@16
|
155 // from
|
Chris@16
|
156 //
|
Chris@16
|
157 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
158 template <typename CharEncoding, typename Tag, bool no_attribute>
|
Chris@16
|
159 struct literal_char
|
Chris@16
|
160 : char_generator<literal_char<CharEncoding, Tag, no_attribute>
|
Chris@16
|
161 , CharEncoding, Tag>
|
Chris@16
|
162 {
|
Chris@16
|
163 typedef typename CharEncoding::char_type char_type;
|
Chris@16
|
164 typedef CharEncoding char_encoding;
|
Chris@16
|
165
|
Chris@16
|
166 literal_char(char_type ch)
|
Chris@16
|
167 : ch (spirit::char_class::convert<char_encoding>::to(Tag(), ch))
|
Chris@16
|
168 {}
|
Chris@16
|
169
|
Chris@16
|
170 template <typename Context, typename Unused>
|
Chris@16
|
171 struct attribute
|
Chris@16
|
172 : mpl::if_c<no_attribute, unused_type, char_type>
|
Chris@16
|
173 {};
|
Chris@16
|
174
|
Chris@16
|
175 // A char_('x') which additionally has an associated attribute emits
|
Chris@16
|
176 // its immediate literal only if it matches the attribute, otherwise
|
Chris@16
|
177 // it fails.
|
Chris@16
|
178 // any_char has an attached parameter
|
Chris@16
|
179 template <typename Attribute, typename CharParam, typename Context>
|
Chris@16
|
180 bool test(Attribute const& attr, CharParam& ch_, Context&) const
|
Chris@16
|
181 {
|
Chris@16
|
182 // fail if attribute isn't matched my immediate literal
|
Chris@16
|
183 ch_ = attr;
|
Chris@16
|
184 return attr == ch;
|
Chris@16
|
185 }
|
Chris@16
|
186
|
Chris@16
|
187 // A char_('x') without any associated attribute just emits its
|
Chris@16
|
188 // immediate literal
|
Chris@16
|
189 template <typename CharParam, typename Context>
|
Chris@16
|
190 bool test(unused_type, CharParam& ch_, Context&) const
|
Chris@16
|
191 {
|
Chris@16
|
192 ch_ = ch;
|
Chris@16
|
193 return true;
|
Chris@16
|
194 }
|
Chris@16
|
195
|
Chris@16
|
196 template <typename Context>
|
Chris@16
|
197 info what(Context const& /*context*/) const
|
Chris@16
|
198 {
|
Chris@16
|
199 return info("literal-char", char_encoding::toucs4(ch));
|
Chris@16
|
200 }
|
Chris@16
|
201
|
Chris@16
|
202 char_type ch;
|
Chris@16
|
203 };
|
Chris@16
|
204
|
Chris@16
|
205 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
206 // char range generator
|
Chris@16
|
207 template <typename CharEncoding, typename Tag>
|
Chris@16
|
208 struct char_range
|
Chris@16
|
209 : char_generator<char_range<CharEncoding, Tag>, CharEncoding, Tag>
|
Chris@16
|
210 {
|
Chris@16
|
211 typedef typename CharEncoding::char_type char_type;
|
Chris@16
|
212 typedef CharEncoding char_encoding;
|
Chris@16
|
213
|
Chris@16
|
214 char_range(char_type from, char_type to)
|
Chris@16
|
215 : from(spirit::char_class::convert<char_encoding>::to(Tag(), from))
|
Chris@16
|
216 , to(spirit::char_class::convert<char_encoding>::to(Tag(), to))
|
Chris@16
|
217 {}
|
Chris@16
|
218
|
Chris@16
|
219 // A char_('a', 'z') which has an associated attribute emits it only if
|
Chris@16
|
220 // it matches the character range, otherwise it fails.
|
Chris@16
|
221 template <typename Attribute, typename CharParam, typename Context>
|
Chris@16
|
222 bool test(Attribute const& attr, CharParam& ch, Context&) const
|
Chris@16
|
223 {
|
Chris@16
|
224 // fail if attribute doesn't belong to character range
|
Chris@16
|
225 ch = attr;
|
Chris@16
|
226 return (from <= char_type(attr)) && (char_type(attr) <= to);
|
Chris@16
|
227 }
|
Chris@16
|
228
|
Chris@16
|
229 // A char_('a', 'z') without any associated attribute fails compiling
|
Chris@16
|
230 template <typename CharParam, typename Context>
|
Chris@16
|
231 bool test(unused_type, CharParam&, Context&) const
|
Chris@16
|
232 {
|
Chris@16
|
233 // It is not possible (doesn't make sense) to use char_ generators
|
Chris@16
|
234 // without providing any attribute, as the generator doesn't 'know'
|
Chris@16
|
235 // what to output. The following assertion fires if this situation
|
Chris@16
|
236 // is detected in your code.
|
Chris@16
|
237 BOOST_SPIRIT_ASSERT_FAIL(CharParam
|
Chris@16
|
238 , char_range_not_usable_without_attribute, ());
|
Chris@16
|
239 return false;
|
Chris@16
|
240 }
|
Chris@16
|
241
|
Chris@16
|
242 template <typename Context>
|
Chris@16
|
243 info what(Context& /*context*/) const
|
Chris@16
|
244 {
|
Chris@16
|
245 info result("char-range", char_encoding::toucs4(from));
|
Chris@16
|
246 boost::get<std::string>(result.value) += '-';
|
Chris@16
|
247 boost::get<std::string>(result.value) += to_utf8(char_encoding::toucs4(to));
|
Chris@16
|
248 return result;
|
Chris@16
|
249 }
|
Chris@16
|
250
|
Chris@16
|
251 char_type from, to;
|
Chris@16
|
252 };
|
Chris@16
|
253
|
Chris@16
|
254 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
255 // character set generator
|
Chris@16
|
256 template <typename CharEncoding, typename Tag, bool no_attribute>
|
Chris@16
|
257 struct char_set
|
Chris@16
|
258 : char_generator<char_set<CharEncoding, Tag, no_attribute>
|
Chris@16
|
259 , CharEncoding, Tag>
|
Chris@16
|
260 {
|
Chris@16
|
261 typedef typename CharEncoding::char_type char_type;
|
Chris@16
|
262 typedef CharEncoding char_encoding;
|
Chris@16
|
263
|
Chris@16
|
264 template <typename Context, typename Unused>
|
Chris@16
|
265 struct attribute
|
Chris@16
|
266 : mpl::if_c<no_attribute, unused_type, char_type>
|
Chris@16
|
267 {};
|
Chris@16
|
268
|
Chris@16
|
269 template <typename String>
|
Chris@16
|
270 char_set(String const& str)
|
Chris@16
|
271 {
|
Chris@16
|
272 typedef typename traits::char_type_of<String>::type in_type;
|
Chris@16
|
273
|
Chris@16
|
274 BOOST_SPIRIT_ASSERT_MSG((
|
Chris@16
|
275 (sizeof(char_type) == sizeof(in_type))
|
Chris@16
|
276 ), cannot_convert_string, (String));
|
Chris@16
|
277
|
Chris@16
|
278 typedef spirit::char_class::convert<char_encoding> convert_type;
|
Chris@16
|
279
|
Chris@16
|
280 char_type const* definition =
|
Chris@16
|
281 (char_type const*)traits::get_c_string(str);
|
Chris@16
|
282 char_type ch = convert_type::to(Tag(), *definition++);
|
Chris@16
|
283 while (ch)
|
Chris@16
|
284 {
|
Chris@16
|
285 char_type next = convert_type::to(Tag(), *definition++);
|
Chris@16
|
286 if (next == '-')
|
Chris@16
|
287 {
|
Chris@16
|
288 next = convert_type::to(Tag(), *definition++);
|
Chris@16
|
289 if (next == 0)
|
Chris@16
|
290 {
|
Chris@16
|
291 chset.set(ch);
|
Chris@16
|
292 chset.set('-');
|
Chris@16
|
293 break;
|
Chris@16
|
294 }
|
Chris@16
|
295 chset.set(ch, next);
|
Chris@16
|
296 }
|
Chris@16
|
297 else
|
Chris@16
|
298 {
|
Chris@16
|
299 chset.set(ch);
|
Chris@16
|
300 }
|
Chris@16
|
301 ch = next;
|
Chris@16
|
302 }
|
Chris@16
|
303 }
|
Chris@16
|
304
|
Chris@16
|
305 // A char_("a-z") which has an associated attribute emits it only if
|
Chris@16
|
306 // it matches the character set, otherwise it fails.
|
Chris@16
|
307 template <typename Attribute, typename CharParam, typename Context>
|
Chris@16
|
308 bool test(Attribute const& attr, CharParam& ch, Context&) const
|
Chris@16
|
309 {
|
Chris@16
|
310 // fail if attribute doesn't belong to character set
|
Chris@16
|
311 ch = attr;
|
Chris@16
|
312 return chset.test(char_type(attr));
|
Chris@16
|
313 }
|
Chris@16
|
314
|
Chris@16
|
315 // A char_("a-z") without any associated attribute fails compiling
|
Chris@16
|
316 template <typename CharParam, typename Context>
|
Chris@16
|
317 bool test(unused_type, CharParam&, Context&) const
|
Chris@16
|
318 {
|
Chris@16
|
319 // It is not possible (doesn't make sense) to use char_ generators
|
Chris@16
|
320 // without providing any attribute, as the generator doesn't 'know'
|
Chris@16
|
321 // what to output. The following assertion fires if this situation
|
Chris@16
|
322 // is detected in your code.
|
Chris@16
|
323 BOOST_SPIRIT_ASSERT_FAIL(CharParam
|
Chris@16
|
324 , char_set_not_usable_without_attribute, ());
|
Chris@16
|
325 return false;
|
Chris@16
|
326 }
|
Chris@16
|
327
|
Chris@16
|
328 template <typename Context>
|
Chris@16
|
329 info what(Context& /*context*/) const
|
Chris@16
|
330 {
|
Chris@16
|
331 return info("char-set");
|
Chris@16
|
332 }
|
Chris@16
|
333
|
Chris@16
|
334 support::detail::basic_chset<char_type> chset;
|
Chris@16
|
335 };
|
Chris@16
|
336
|
Chris@16
|
337 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
338 // Generator generators: make_xxx function (objects)
|
Chris@16
|
339 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
340 namespace detail
|
Chris@16
|
341 {
|
Chris@16
|
342 template <typename Modifiers, typename Encoding>
|
Chris@16
|
343 struct basic_literal
|
Chris@16
|
344 {
|
Chris@16
|
345 static bool const lower =
|
Chris@16
|
346 has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
|
Chris@16
|
347 static bool const upper =
|
Chris@16
|
348 has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
|
Chris@16
|
349
|
Chris@16
|
350 typedef literal_char<
|
Chris@16
|
351 typename spirit::detail::get_encoding_with_case<
|
Chris@16
|
352 Modifiers, Encoding, lower || upper>::type
|
Chris@16
|
353 , typename get_casetag<Modifiers, lower || upper>::type
|
Chris@16
|
354 , true>
|
Chris@16
|
355 result_type;
|
Chris@16
|
356
|
Chris@16
|
357 template <typename Char>
|
Chris@16
|
358 result_type operator()(Char ch, unused_type) const
|
Chris@16
|
359 {
|
Chris@16
|
360 return result_type(ch);
|
Chris@16
|
361 }
|
Chris@16
|
362
|
Chris@16
|
363 template <typename Char>
|
Chris@16
|
364 result_type operator()(Char const* str, unused_type) const
|
Chris@16
|
365 {
|
Chris@16
|
366 return result_type(str[0]);
|
Chris@16
|
367 }
|
Chris@16
|
368 };
|
Chris@16
|
369 }
|
Chris@16
|
370
|
Chris@16
|
371 // literals: 'x', "x"
|
Chris@16
|
372 template <typename Modifiers>
|
Chris@16
|
373 struct make_primitive<char, Modifiers>
|
Chris@16
|
374 : detail::basic_literal<Modifiers, char_encoding::standard> {};
|
Chris@16
|
375
|
Chris@16
|
376 template <typename Modifiers>
|
Chris@16
|
377 struct make_primitive<char const(&)[2], Modifiers>
|
Chris@16
|
378 : detail::basic_literal<Modifiers, char_encoding::standard> {};
|
Chris@16
|
379
|
Chris@16
|
380 // literals: L'x', L"x"
|
Chris@16
|
381 template <typename Modifiers>
|
Chris@16
|
382 struct make_primitive<wchar_t, Modifiers>
|
Chris@16
|
383 : detail::basic_literal<Modifiers, char_encoding::standard_wide> {};
|
Chris@16
|
384
|
Chris@16
|
385 template <typename Modifiers>
|
Chris@16
|
386 struct make_primitive<wchar_t const(&)[2], Modifiers>
|
Chris@16
|
387 : detail::basic_literal<Modifiers, char_encoding::standard_wide> {};
|
Chris@16
|
388
|
Chris@16
|
389 // char_
|
Chris@16
|
390 template <typename CharEncoding, typename Modifiers>
|
Chris@16
|
391 struct make_primitive<tag::char_code<tag::char_, CharEncoding>, Modifiers>
|
Chris@16
|
392 {
|
Chris@16
|
393 static bool const lower =
|
Chris@16
|
394 has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
|
Chris@16
|
395 static bool const upper =
|
Chris@16
|
396 has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
|
Chris@16
|
397
|
Chris@16
|
398 typedef any_char<
|
Chris@16
|
399 typename spirit::detail::get_encoding_with_case<
|
Chris@16
|
400 Modifiers, CharEncoding, lower || upper>::type
|
Chris@16
|
401 , typename detail::get_casetag<Modifiers, lower || upper>::type
|
Chris@16
|
402 > result_type;
|
Chris@16
|
403
|
Chris@16
|
404 result_type operator()(unused_type, unused_type) const
|
Chris@16
|
405 {
|
Chris@16
|
406 return result_type();
|
Chris@16
|
407 }
|
Chris@16
|
408 };
|
Chris@16
|
409
|
Chris@16
|
410 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
411 namespace detail
|
Chris@16
|
412 {
|
Chris@16
|
413 template <typename CharEncoding, typename Modifiers, typename A0
|
Chris@16
|
414 , bool no_attribute>
|
Chris@16
|
415 struct make_char_direct
|
Chris@16
|
416 {
|
Chris@16
|
417 static bool const lower =
|
Chris@16
|
418 has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
|
Chris@16
|
419 static bool const upper =
|
Chris@16
|
420 has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
|
Chris@16
|
421
|
Chris@16
|
422 typedef typename spirit::detail::get_encoding_with_case<
|
Chris@16
|
423 Modifiers, CharEncoding, lower || upper>::type encoding;
|
Chris@16
|
424 typedef typename detail::get_casetag<
|
Chris@16
|
425 Modifiers, lower || upper>::type tag;
|
Chris@16
|
426
|
Chris@16
|
427 typedef typename mpl::if_<
|
Chris@16
|
428 traits::is_string<A0>
|
Chris@16
|
429 , char_set<encoding, tag, no_attribute>
|
Chris@16
|
430 , literal_char<encoding, tag, no_attribute>
|
Chris@16
|
431 >::type result_type;
|
Chris@16
|
432
|
Chris@16
|
433 template <typename Terminal>
|
Chris@16
|
434 result_type operator()(Terminal const& term, unused_type) const
|
Chris@16
|
435 {
|
Chris@16
|
436 return result_type(fusion::at_c<0>(term.args));
|
Chris@16
|
437 }
|
Chris@16
|
438 };
|
Chris@16
|
439 }
|
Chris@16
|
440
|
Chris@16
|
441 // char_(...), lit(...)
|
Chris@16
|
442 template <typename CharEncoding, typename Modifiers, typename A0>
|
Chris@16
|
443 struct make_primitive<
|
Chris@16
|
444 terminal_ex<
|
Chris@16
|
445 tag::char_code<tag::char_, CharEncoding>
|
Chris@16
|
446 , fusion::vector1<A0> >
|
Chris@16
|
447 , Modifiers>
|
Chris@16
|
448 : detail::make_char_direct<CharEncoding, Modifiers, A0, false>
|
Chris@16
|
449 {};
|
Chris@16
|
450
|
Chris@16
|
451 template <typename Modifiers, typename A0>
|
Chris@16
|
452 struct make_primitive<
|
Chris@16
|
453 terminal_ex<tag::lit, fusion::vector1<A0> >
|
Chris@16
|
454 , Modifiers
|
Chris@16
|
455 , typename enable_if<traits::is_char<A0> >::type>
|
Chris@16
|
456 : detail::make_char_direct<
|
Chris@16
|
457 typename traits::char_encoding_from_char<
|
Chris@16
|
458 typename traits::char_type_of<A0>::type>::type
|
Chris@16
|
459 , Modifiers, A0, true>
|
Chris@16
|
460 {};
|
Chris@16
|
461
|
Chris@16
|
462 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
463 // char_("x")
|
Chris@16
|
464 template <typename CharEncoding, typename Modifiers, typename Char>
|
Chris@16
|
465 struct make_primitive<
|
Chris@16
|
466 terminal_ex<
|
Chris@16
|
467 tag::char_code<tag::char_, CharEncoding>
|
Chris@16
|
468 , fusion::vector1<Char(&)[2]> > // For single char strings
|
Chris@16
|
469 , Modifiers>
|
Chris@16
|
470 {
|
Chris@16
|
471 static bool const lower =
|
Chris@16
|
472 has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
|
Chris@16
|
473 static bool const upper =
|
Chris@16
|
474 has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
|
Chris@16
|
475
|
Chris@16
|
476 typedef literal_char<
|
Chris@16
|
477 typename spirit::detail::get_encoding_with_case<
|
Chris@16
|
478 Modifiers, CharEncoding, lower || upper>::type
|
Chris@16
|
479 , typename detail::get_casetag<Modifiers, lower || upper>::type
|
Chris@16
|
480 , false
|
Chris@16
|
481 > result_type;
|
Chris@16
|
482
|
Chris@16
|
483 template <typename Terminal>
|
Chris@16
|
484 result_type operator()(Terminal const& term, unused_type) const
|
Chris@16
|
485 {
|
Chris@16
|
486 return result_type(fusion::at_c<0>(term.args)[0]);
|
Chris@16
|
487 }
|
Chris@16
|
488 };
|
Chris@16
|
489
|
Chris@16
|
490 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
491 // char_('a', 'z')
|
Chris@16
|
492 template <typename CharEncoding, typename Modifiers, typename A0, typename A1>
|
Chris@16
|
493 struct make_primitive<
|
Chris@16
|
494 terminal_ex<
|
Chris@16
|
495 tag::char_code<tag::char_, CharEncoding>
|
Chris@16
|
496 , fusion::vector2<A0, A1>
|
Chris@16
|
497 >
|
Chris@16
|
498 , Modifiers>
|
Chris@16
|
499 {
|
Chris@16
|
500 static bool const lower =
|
Chris@16
|
501 has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
|
Chris@16
|
502 static bool const upper =
|
Chris@16
|
503 has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
|
Chris@16
|
504
|
Chris@16
|
505 typedef char_range<
|
Chris@16
|
506 typename spirit::detail::get_encoding_with_case<
|
Chris@16
|
507 Modifiers, CharEncoding, lower || upper>::type
|
Chris@16
|
508 , typename detail::get_casetag<Modifiers, lower || upper>::type
|
Chris@16
|
509 > result_type;
|
Chris@16
|
510
|
Chris@16
|
511 template <typename Terminal>
|
Chris@16
|
512 result_type operator()(Terminal const& term, unused_type) const
|
Chris@16
|
513 {
|
Chris@16
|
514 return result_type(fusion::at_c<0>(term.args)
|
Chris@16
|
515 , fusion::at_c<1>(term.args));
|
Chris@16
|
516 }
|
Chris@16
|
517 };
|
Chris@16
|
518
|
Chris@16
|
519 template <typename CharEncoding, typename Modifiers, typename Char>
|
Chris@16
|
520 struct make_primitive<
|
Chris@16
|
521 terminal_ex<
|
Chris@16
|
522 tag::char_code<tag::char_, CharEncoding>
|
Chris@16
|
523 , fusion::vector2<Char(&)[2], Char(&)[2]> // For single char strings
|
Chris@16
|
524 >
|
Chris@16
|
525 , Modifiers>
|
Chris@16
|
526 {
|
Chris@16
|
527 static bool const lower =
|
Chris@16
|
528 has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
|
Chris@16
|
529 static bool const upper =
|
Chris@16
|
530 has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
|
Chris@16
|
531
|
Chris@16
|
532 typedef char_range<
|
Chris@16
|
533 typename spirit::detail::get_encoding_with_case<
|
Chris@16
|
534 Modifiers, CharEncoding, lower || upper>::type
|
Chris@16
|
535 , typename detail::get_casetag<Modifiers, lower || upper>::type
|
Chris@16
|
536 > result_type;
|
Chris@16
|
537
|
Chris@16
|
538 template <typename Terminal>
|
Chris@16
|
539 result_type operator()(Terminal const& term, unused_type) const
|
Chris@16
|
540 {
|
Chris@16
|
541 return result_type(fusion::at_c<0>(term.args)[0]
|
Chris@16
|
542 , fusion::at_c<1>(term.args)[0]);
|
Chris@16
|
543 }
|
Chris@16
|
544 };
|
Chris@16
|
545 }}} // namespace boost::spirit::karma
|
Chris@16
|
546
|
Chris@16
|
547 #endif
|