Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Copyright (c) 2001-2011 Hartmut Kaiser
|
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_DETAIL_PARSE_AUTO_DEC_02_2009_0426PM)
|
Chris@16
|
8 #define BOOST_SPIRIT_DETAIL_PARSE_AUTO_DEC_02_2009_0426PM
|
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/qi/parse.hpp>
|
Chris@16
|
15 #include <boost/spirit/home/qi/auto/create_parser.hpp>
|
Chris@16
|
16 #include <boost/utility/enable_if.hpp>
|
Chris@16
|
17 #include <boost/mpl/not.hpp>
|
Chris@16
|
18 #include <boost/mpl/and.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 namespace boost { namespace spirit { namespace qi { namespace detail
|
Chris@16
|
21 {
|
Chris@16
|
22 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
23 template <typename Expr>
|
Chris@16
|
24 struct parse_impl<Expr
|
Chris@16
|
25 , typename enable_if<
|
Chris@16
|
26 mpl::and_<
|
Chris@16
|
27 traits::meta_create_exists<qi::domain, Expr>
|
Chris@16
|
28 , mpl::not_<traits::matches<qi::domain, Expr> > >
|
Chris@16
|
29 >::type>
|
Chris@16
|
30 {
|
Chris@16
|
31 template <typename Iterator>
|
Chris@16
|
32 static bool call(Iterator& first, Iterator last, Expr& expr)
|
Chris@16
|
33 {
|
Chris@16
|
34 return qi::parse(first, last, create_parser<Expr>(), expr);
|
Chris@16
|
35 }
|
Chris@16
|
36
|
Chris@16
|
37 template <typename Iterator>
|
Chris@16
|
38 static bool call(Iterator& first, Iterator last, Expr const& expr)
|
Chris@16
|
39 {
|
Chris@16
|
40 return qi::parse(first, last, create_parser<Expr>()
|
Chris@16
|
41 , const_cast<Expr&>(expr));
|
Chris@16
|
42 }
|
Chris@16
|
43 };
|
Chris@16
|
44
|
Chris@16
|
45 // the following specializations are needed to explicitly disambiguate
|
Chris@16
|
46 // the two possible specializations for parse_impl<char> and
|
Chris@16
|
47 // parse_impl<wchar_t>
|
Chris@16
|
48 template <>
|
Chris@16
|
49 struct parse_impl<char>
|
Chris@16
|
50 {
|
Chris@16
|
51 template <typename Iterator>
|
Chris@16
|
52 static bool call(Iterator& first, Iterator last, char& expr)
|
Chris@16
|
53 {
|
Chris@16
|
54 return qi::parse(first, last, create_parser<char>(), expr);
|
Chris@16
|
55 }
|
Chris@16
|
56
|
Chris@16
|
57 template <typename Iterator>
|
Chris@16
|
58 static bool call(Iterator& first, Iterator last, char const&)
|
Chris@16
|
59 {
|
Chris@16
|
60 return qi::parse(first, last, create_parser<char>());
|
Chris@16
|
61 }
|
Chris@16
|
62 };
|
Chris@16
|
63
|
Chris@16
|
64 template <>
|
Chris@16
|
65 struct parse_impl<wchar_t>
|
Chris@16
|
66 {
|
Chris@16
|
67 template <typename Iterator>
|
Chris@16
|
68 static bool call(Iterator& first, Iterator last, wchar_t& expr)
|
Chris@16
|
69 {
|
Chris@16
|
70 return qi::parse(first, last, create_parser<wchar_t>(), expr);
|
Chris@16
|
71 }
|
Chris@16
|
72
|
Chris@16
|
73 template <typename Iterator>
|
Chris@16
|
74 static bool call(Iterator& first, Iterator last, wchar_t const&)
|
Chris@16
|
75 {
|
Chris@16
|
76 return qi::parse(first, last, create_parser<wchar_t>());
|
Chris@16
|
77 }
|
Chris@16
|
78 };
|
Chris@16
|
79
|
Chris@16
|
80 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
81 template <typename Expr>
|
Chris@16
|
82 struct phrase_parse_impl<Expr
|
Chris@16
|
83 , typename enable_if<
|
Chris@16
|
84 mpl::and_<
|
Chris@16
|
85 traits::meta_create_exists<qi::domain, Expr>
|
Chris@16
|
86 , mpl::not_<traits::matches<qi::domain, Expr> > >
|
Chris@16
|
87 >::type>
|
Chris@16
|
88 {
|
Chris@16
|
89 template <typename Iterator, typename Skipper>
|
Chris@16
|
90 static bool call(Iterator& first, Iterator last, Expr& expr
|
Chris@16
|
91 , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
|
Chris@16
|
92 {
|
Chris@16
|
93 return qi::phrase_parse(first, last, create_parser<Expr>()
|
Chris@16
|
94 , skipper, post_skip, expr);
|
Chris@16
|
95 }
|
Chris@16
|
96
|
Chris@16
|
97 template <typename Iterator, typename Skipper>
|
Chris@16
|
98 static bool call(Iterator& first, Iterator last, Expr const& expr
|
Chris@16
|
99 , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
|
Chris@16
|
100 {
|
Chris@16
|
101 return qi::phrase_parse(first, last, create_parser<Expr>()
|
Chris@16
|
102 , skipper, post_skip, const_cast<Expr&>(expr));
|
Chris@16
|
103 }
|
Chris@16
|
104 };
|
Chris@16
|
105
|
Chris@16
|
106 // the following specializations are needed to explicitly disambiguate
|
Chris@16
|
107 // the two possible specializations for phrase_parse_impl<char> and
|
Chris@16
|
108 // phrase_parse_impl<wchar_t>
|
Chris@16
|
109 template <>
|
Chris@16
|
110 struct phrase_parse_impl<char>
|
Chris@16
|
111 {
|
Chris@16
|
112 template <typename Iterator, typename Skipper>
|
Chris@16
|
113 static bool call(Iterator& first, Iterator last, char& expr
|
Chris@16
|
114 , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
|
Chris@16
|
115 {
|
Chris@16
|
116 return qi::phrase_parse(first, last, create_parser<char>()
|
Chris@16
|
117 , skipper, post_skip, expr);
|
Chris@16
|
118 }
|
Chris@16
|
119
|
Chris@16
|
120 template <typename Iterator, typename Skipper>
|
Chris@16
|
121 static bool call(Iterator& first, Iterator last, char const&
|
Chris@16
|
122 , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
|
Chris@16
|
123 {
|
Chris@16
|
124 return qi::phrase_parse(first, last, create_parser<char>()
|
Chris@16
|
125 , skipper, post_skip);
|
Chris@16
|
126 }
|
Chris@16
|
127 };
|
Chris@16
|
128
|
Chris@16
|
129 template <>
|
Chris@16
|
130 struct phrase_parse_impl<wchar_t>
|
Chris@16
|
131 {
|
Chris@16
|
132 template <typename Iterator, typename Skipper>
|
Chris@16
|
133 static bool call(Iterator& first, Iterator last, wchar_t& expr
|
Chris@16
|
134 , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
|
Chris@16
|
135 {
|
Chris@16
|
136 return qi::phrase_parse(first, last, create_parser<wchar_t>()
|
Chris@16
|
137 , skipper, post_skip, expr);
|
Chris@16
|
138 }
|
Chris@16
|
139
|
Chris@16
|
140 template <typename Iterator, typename Skipper>
|
Chris@16
|
141 static bool call(Iterator& first, Iterator last, wchar_t const&
|
Chris@16
|
142 , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
|
Chris@16
|
143 {
|
Chris@16
|
144 return qi::phrase_parse(first, last, create_parser<wchar_t>()
|
Chris@16
|
145 , skipper, post_skip);
|
Chris@16
|
146 }
|
Chris@16
|
147 };
|
Chris@16
|
148 }}}}
|
Chris@16
|
149
|
Chris@16
|
150 namespace boost { namespace spirit { namespace qi
|
Chris@16
|
151 {
|
Chris@16
|
152 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
153 template <typename Iterator, typename Expr>
|
Chris@16
|
154 inline bool
|
Chris@16
|
155 parse(
|
Chris@16
|
156 Iterator& first
|
Chris@16
|
157 , Iterator last
|
Chris@16
|
158 , Expr& expr)
|
Chris@16
|
159 {
|
Chris@16
|
160 // Make sure the iterator is at least a forward_iterator. If you got a
|
Chris@16
|
161 // compilation error here, then you are using an input_iterator while
|
Chris@16
|
162 // calling this function, you need to supply at least a
|
Chris@16
|
163 // forward_iterator instead.
|
Chris@16
|
164 BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
|
Chris@16
|
165
|
Chris@16
|
166 return detail::parse_impl<Expr>::call(first, last, expr);
|
Chris@16
|
167 }
|
Chris@16
|
168
|
Chris@16
|
169 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
170 template <typename Iterator, typename Expr, typename Skipper>
|
Chris@16
|
171 inline bool
|
Chris@16
|
172 phrase_parse(
|
Chris@16
|
173 Iterator& first
|
Chris@16
|
174 , Iterator last
|
Chris@16
|
175 , Expr& expr
|
Chris@16
|
176 , Skipper const& skipper
|
Chris@16
|
177 , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip)
|
Chris@16
|
178 {
|
Chris@16
|
179 // Make sure the iterator is at least a forward_iterator. If you got a
|
Chris@16
|
180 // compilation error here, then you are using an input_iterator while
|
Chris@16
|
181 // calling this function, you need to supply at least a
|
Chris@16
|
182 // forward_iterator instead.
|
Chris@16
|
183 BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
|
Chris@16
|
184
|
Chris@16
|
185 return detail::phrase_parse_impl<Expr>::call(
|
Chris@16
|
186 first, last, expr, skipper, post_skip);
|
Chris@16
|
187 }
|
Chris@16
|
188 }}}
|
Chris@16
|
189
|
Chris@16
|
190 #endif
|
Chris@16
|
191
|