]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2001-2011 Hartmut Kaiser | |
3 | ||
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 | |
9 | ||
10 | #if defined(_MSC_VER) | |
11 | #pragma once | |
12 | #endif | |
13 | ||
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> | |
19 | ||
20 | namespace boost { namespace spirit { namespace qi { namespace detail | |
21 | { | |
22 | /////////////////////////////////////////////////////////////////////////// | |
23 | template <typename Expr> | |
24 | struct parse_impl<Expr | |
25 | , typename enable_if< | |
26 | mpl::and_< | |
27 | traits::meta_create_exists<qi::domain, Expr> | |
28 | , mpl::not_<traits::matches<qi::domain, Expr> > > | |
29 | >::type> | |
30 | { | |
31 | template <typename Iterator> | |
32 | static bool call(Iterator& first, Iterator last, Expr& expr) | |
33 | { | |
34 | return qi::parse(first, last, create_parser<Expr>(), expr); | |
35 | } | |
36 | ||
37 | template <typename Iterator> | |
38 | static bool call(Iterator& first, Iterator last, Expr const& expr) | |
39 | { | |
40 | return qi::parse(first, last, create_parser<Expr>() | |
41 | , const_cast<Expr&>(expr)); | |
42 | } | |
43 | }; | |
44 | ||
45 | // the following specializations are needed to explicitly disambiguate | |
46 | // the two possible specializations for parse_impl<char> and | |
47 | // parse_impl<wchar_t> | |
48 | template <> | |
49 | struct parse_impl<char> | |
50 | { | |
51 | template <typename Iterator> | |
52 | static bool call(Iterator& first, Iterator last, char& expr) | |
53 | { | |
54 | return qi::parse(first, last, create_parser<char>(), expr); | |
55 | } | |
56 | ||
57 | template <typename Iterator> | |
58 | static bool call(Iterator& first, Iterator last, char const&) | |
59 | { | |
60 | return qi::parse(first, last, create_parser<char>()); | |
61 | } | |
62 | }; | |
63 | ||
64 | template <> | |
65 | struct parse_impl<wchar_t> | |
66 | { | |
67 | template <typename Iterator> | |
68 | static bool call(Iterator& first, Iterator last, wchar_t& expr) | |
69 | { | |
70 | return qi::parse(first, last, create_parser<wchar_t>(), expr); | |
71 | } | |
72 | ||
73 | template <typename Iterator> | |
74 | static bool call(Iterator& first, Iterator last, wchar_t const&) | |
75 | { | |
76 | return qi::parse(first, last, create_parser<wchar_t>()); | |
77 | } | |
78 | }; | |
79 | ||
80 | /////////////////////////////////////////////////////////////////////////// | |
81 | template <typename Expr> | |
82 | struct phrase_parse_impl<Expr | |
83 | , typename enable_if< | |
84 | mpl::and_< | |
85 | traits::meta_create_exists<qi::domain, Expr> | |
86 | , mpl::not_<traits::matches<qi::domain, Expr> > > | |
87 | >::type> | |
88 | { | |
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) | |
92 | { | |
93 | return qi::phrase_parse(first, last, create_parser<Expr>() | |
94 | , skipper, post_skip, expr); | |
95 | } | |
96 | ||
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) | |
100 | { | |
101 | return qi::phrase_parse(first, last, create_parser<Expr>() | |
102 | , skipper, post_skip, const_cast<Expr&>(expr)); | |
103 | } | |
104 | }; | |
105 | ||
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> | |
109 | template <> | |
110 | struct phrase_parse_impl<char> | |
111 | { | |
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) | |
115 | { | |
116 | return qi::phrase_parse(first, last, create_parser<char>() | |
117 | , skipper, post_skip, expr); | |
118 | } | |
119 | ||
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) | |
123 | { | |
124 | return qi::phrase_parse(first, last, create_parser<char>() | |
125 | , skipper, post_skip); | |
126 | } | |
127 | }; | |
128 | ||
129 | template <> | |
130 | struct phrase_parse_impl<wchar_t> | |
131 | { | |
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) | |
135 | { | |
136 | return qi::phrase_parse(first, last, create_parser<wchar_t>() | |
137 | , skipper, post_skip, expr); | |
138 | } | |
139 | ||
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) | |
143 | { | |
144 | return qi::phrase_parse(first, last, create_parser<wchar_t>() | |
145 | , skipper, post_skip); | |
146 | } | |
147 | }; | |
148 | }}}} | |
149 | ||
150 | namespace boost { namespace spirit { namespace qi | |
151 | { | |
152 | /////////////////////////////////////////////////////////////////////////// | |
153 | template <typename Iterator, typename Expr> | |
154 | inline bool | |
155 | parse( | |
156 | Iterator& first | |
157 | , Iterator last | |
158 | , Expr& expr) | |
159 | { | |
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>)); | |
165 | ||
166 | return detail::parse_impl<Expr>::call(first, last, expr); | |
167 | } | |
168 | ||
169 | /////////////////////////////////////////////////////////////////////////// | |
170 | template <typename Iterator, typename Expr, typename Skipper> | |
171 | inline bool | |
172 | phrase_parse( | |
173 | Iterator& first | |
174 | , Iterator last | |
175 | , Expr& expr | |
176 | , Skipper const& skipper | |
177 | , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip) | |
178 | { | |
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>)); | |
184 | ||
185 | return detail::phrase_parse_impl<Expr>::call( | |
186 | first, last, expr, skipper, post_skip); | |
187 | } | |
188 | }}} | |
189 | ||
190 | #endif | |
191 |