1 /*=============================================================================
2 Copyright (c) 2002-2003 Joel de Guzman
3 Copyright (c) 2002-2003 Hartmut Kaiser
4 http://spirit.sourceforge.net/
6 Distributed under the Boost Software License, Version 1.0. (See accompanying
7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 #if !defined(BOOST_SPIRIT_AS_PARSER_HPP)
10 #define BOOST_SPIRIT_AS_PARSER_HPP
12 #include <boost/spirit/home/classic/namespace.hpp>
13 #include <boost/spirit/home/classic/core/primitives/primitives.hpp>
15 namespace boost { namespace spirit {
17 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
19 ///////////////////////////////////////////////////////////////////////////
21 // Helper templates to derive the parser type from an auxilliary type
22 // and to generate an object of the required parser type given an
23 // auxilliary object. Supported types to convert are parsers,
24 // single characters and character strings.
26 ///////////////////////////////////////////////////////////////////////////
30 struct default_as_parser
33 static type const& convert(type const& p)
41 typedef chlit<char> type;
42 static type convert(char ch)
48 struct wchar_as_parser
50 typedef chlit<wchar_t> type;
51 static type convert(wchar_t ch)
57 struct string_as_parser
59 typedef strlit<char const*> type;
60 static type convert(char const* str)
66 struct wstring_as_parser
68 typedef strlit<wchar_t const*> type;
69 static type convert(wchar_t const* str)
77 struct as_parser : impl::default_as_parser<T> {};
80 struct as_parser<char> : impl::char_as_parser {};
83 struct as_parser<wchar_t> : impl::wchar_as_parser {};
86 struct as_parser<char*> : impl::string_as_parser {};
89 struct as_parser<char const*> : impl::string_as_parser {};
92 struct as_parser<wchar_t*> : impl::wstring_as_parser {};
95 struct as_parser<wchar_t const*> : impl::wstring_as_parser {};
98 struct as_parser<char[N]> : impl::string_as_parser {};
101 struct as_parser<wchar_t[N]> : impl::wstring_as_parser {};
104 struct as_parser<char const[N]> : impl::string_as_parser {};
107 struct as_parser<wchar_t const[N]> : impl::wstring_as_parser {};
109 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
111 }} // namespace BOOST_SPIRIT_CLASSIC_NS