1 /*=============================================================================
2 Copyright (c) 2001-2011 Hartmut Kaiser
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 =============================================================================*/
7 #if !defined(BOOST_SPIRIT_DETAIL_PARSE_AUTO_DEC_02_2009_0426PM)
8 #define BOOST_SPIRIT_DETAIL_PARSE_AUTO_DEC_02_2009_0426PM
14 #include <boost/spirit/home/qi/parse.hpp>
15 #include <boost/spirit/home/qi/auto/create_parser.hpp>
16 #include <boost/utility/enable_if.hpp>
17 #include <boost/mpl/not.hpp>
18 #include <boost/mpl/and.hpp>
20 namespace boost { namespace spirit { namespace qi { namespace detail
22 ///////////////////////////////////////////////////////////////////////////
23 template <typename Expr>
24 struct parse_impl<Expr
27 traits::meta_create_exists<qi::domain, Expr>
28 , mpl::not_<traits::matches<qi::domain, Expr> > >
31 template <typename Iterator>
32 static bool call(Iterator& first, Iterator last, Expr& expr)
34 return qi::parse(first, last, create_parser<Expr>(), expr);
37 template <typename Iterator>
38 static bool call(Iterator& first, Iterator last, Expr const& expr)
40 return qi::parse(first, last, create_parser<Expr>()
41 , const_cast<Expr&>(expr));
45 // the following specializations are needed to explicitly disambiguate
46 // the two possible specializations for parse_impl<char> and
47 // parse_impl<wchar_t>
49 struct parse_impl<char>
51 template <typename Iterator>
52 static bool call(Iterator& first, Iterator last, char& expr)
54 return qi::parse(first, last, create_parser<char>(), expr);
57 template <typename Iterator>
58 static bool call(Iterator& first, Iterator last, char const&)
60 return qi::parse(first, last, create_parser<char>());
65 struct parse_impl<wchar_t>
67 template <typename Iterator>
68 static bool call(Iterator& first, Iterator last, wchar_t& expr)
70 return qi::parse(first, last, create_parser<wchar_t>(), expr);
73 template <typename Iterator>
74 static bool call(Iterator& first, Iterator last, wchar_t const&)
76 return qi::parse(first, last, create_parser<wchar_t>());
80 ///////////////////////////////////////////////////////////////////////////
81 template <typename Expr>
82 struct phrase_parse_impl<Expr
85 traits::meta_create_exists<qi::domain, Expr>
86 , mpl::not_<traits::matches<qi::domain, Expr> > >
89 template <typename Iterator, typename Skipper>
90 static bool call(Iterator& first, Iterator last, Expr& expr
91 , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
93 return qi::phrase_parse(first, last, create_parser<Expr>()
94 , skipper, post_skip, expr);
97 template <typename Iterator, typename Skipper>
98 static bool call(Iterator& first, Iterator last, Expr const& expr
99 , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
101 return qi::phrase_parse(first, last, create_parser<Expr>()
102 , skipper, post_skip, const_cast<Expr&>(expr));
106 // the following specializations are needed to explicitly disambiguate
107 // the two possible specializations for phrase_parse_impl<char> and
108 // phrase_parse_impl<wchar_t>
110 struct phrase_parse_impl<char>
112 template <typename Iterator, typename Skipper>
113 static bool call(Iterator& first, Iterator last, char& expr
114 , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
116 return qi::phrase_parse(first, last, create_parser<char>()
117 , skipper, post_skip, expr);
120 template <typename Iterator, typename Skipper>
121 static bool call(Iterator& first, Iterator last, char const&
122 , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
124 return qi::phrase_parse(first, last, create_parser<char>()
125 , skipper, post_skip);
130 struct phrase_parse_impl<wchar_t>
132 template <typename Iterator, typename Skipper>
133 static bool call(Iterator& first, Iterator last, wchar_t& expr
134 , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
136 return qi::phrase_parse(first, last, create_parser<wchar_t>()
137 , skipper, post_skip, expr);
140 template <typename Iterator, typename Skipper>
141 static bool call(Iterator& first, Iterator last, wchar_t const&
142 , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
144 return qi::phrase_parse(first, last, create_parser<wchar_t>()
145 , skipper, post_skip);
150 namespace boost { namespace spirit { namespace qi
152 ///////////////////////////////////////////////////////////////////////////
153 template <typename Iterator, typename Expr>
160 // Make sure the iterator is at least a forward_iterator. If you got a
161 // compilation error here, then you are using an input_iterator while
162 // calling this function, you need to supply at least a
163 // forward_iterator instead.
164 BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
166 return detail::parse_impl<Expr>::call(first, last, expr);
169 ///////////////////////////////////////////////////////////////////////////
170 template <typename Iterator, typename Expr, typename Skipper>
176 , Skipper const& skipper
177 , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip)
179 // Make sure the iterator is at least a forward_iterator. If you got a
180 // compilation error here, then you are using an input_iterator while
181 // calling this function, you need to supply at least a
182 // forward_iterator instead.
183 BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
185 return detail::phrase_parse_impl<Expr>::call(
186 first, last, expr, skipper, post_skip);