]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/spirit/include/boost/spirit/home/x3/core/parse.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / spirit / include / boost / spirit / home / x3 / core / parse.hpp
CommitLineData
7c673cae
FG
1/*=============================================================================
2 Copyright (c) 2001-2014 Joel de Guzman
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_X3_PARSE_APRIL_16_2006_0442PM)
8#define BOOST_SPIRIT_X3_PARSE_APRIL_16_2006_0442PM
9
10#include <boost/spirit/home/x3/support/context.hpp>
11#include <boost/spirit/home/x3/core/parser.hpp>
12#include <boost/spirit/home/x3/core/skip_over.hpp>
13#include <boost/concept_check.hpp>
14
15namespace boost { namespace spirit { namespace x3
16{
17 ///////////////////////////////////////////////////////////////////////////
18 template <typename Iterator, typename Parser, typename Attribute>
19 inline bool
20 parse_main(
21 Iterator& first
22 , Iterator last
23 , Parser const& p
24 , Attribute& attr)
25 {
26 // Make sure the iterator is at least a forward_iterator. If you got a
27 // compilation error here, then you are using an input_iterator while
28 // calling this function. You need to supply at least a forward_iterator
29 // instead.
30 BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
31
32 // If you get an error no matching function for call to 'as_parser'
33 // here, then p is not a parser or there is no suitable conversion
34 // from p to a parser.
35 return as_parser(p).parse(first, last, unused, unused, attr);
36 }
37
38 ///////////////////////////////////////////////////////////////////////////
39 template <typename Iterator, typename Parser, typename Attribute>
40 inline bool
41 parse(
42 Iterator& first
43 , Iterator last
44 , Parser const& p
45 , Attribute& attr)
46 {
47 return parse_main(first, last, p, attr);
48 }
49
50 ///////////////////////////////////////////////////////////////////////////
51 template <typename Iterator, typename Parser, typename Attribute>
52 inline bool
53 parse(
54 Iterator const& first_
55 , Iterator last
56 , Parser const& p
57 , Attribute& attr)
58 {
59 Iterator first = first_;
60 return parse_main(first, last, p, attr);
61 }
62
63 ///////////////////////////////////////////////////////////////////////////
64 template <typename Iterator, typename Parser>
65 inline bool
66 parse(
67 Iterator& first
68 , Iterator last
69 , Parser const& p)
70 {
71 return parse_main(first, last, p, unused);
72 }
73
74 ///////////////////////////////////////////////////////////////////////////
75 template <typename Iterator, typename Parser>
76 inline bool
77 parse(
78 Iterator const& first_
79 , Iterator last
80 , Parser const& p)
81 {
82 Iterator first = first_;
83 return parse_main(first, last, p, unused);
84 }
85
86 ///////////////////////////////////////////////////////////////////////////
87 enum class skip_flag
88 {
89 post_skip, // force post-skipping in phrase_parse()
90 dont_post_skip // inhibit post-skipping in phrase_parse()
91 };
92
93 ///////////////////////////////////////////////////////////////////////////
94 template <typename Iterator, typename Parser, typename Skipper, typename Attribute>
95 inline bool
96 phrase_parse_main(
97 Iterator& first
98 , Iterator last
99 , Parser const& p
100 , Skipper const& s
101 , Attribute& attr
102 , skip_flag post_skip = skip_flag::post_skip)
103 {
104 // Make sure the iterator is at least a forward_iterator. If you got a
105 // compilation error here, then you are using an input_iterator while
106 // calling this function. You need to supply at least a forward_iterator
107 // instead.
108 BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
109
110 static_assert(!std::is_same<Skipper, unused_type>::value,
111 "Error! Skipper cannot be unused_type.");
112
113 // If you get an error no matching function for call to 'as_parser'
114 // here, for either p or s, then p or s is not a parser or there is
115 // no suitable conversion from p to a parser.
116 auto skipper_ctx = make_context<skipper_tag>(as_parser(s));
117 bool r = as_parser(p).parse(first, last, skipper_ctx, unused, attr);
118 if (post_skip == skip_flag::post_skip)
119 x3::skip_over(first, last, skipper_ctx);
120 return r;
121 }
122
123 ///////////////////////////////////////////////////////////////////////////
124 template <typename Iterator, typename Parser, typename Skipper, typename Attribute>
125 inline bool
126 phrase_parse(
127 Iterator& first
128 , Iterator last
129 , Parser const& p
130 , Skipper const& s
131 , Attribute& attr
132 , skip_flag post_skip = skip_flag::post_skip)
133 {
134 return phrase_parse_main(first, last, p, s, attr, post_skip);
135 }
136
137 ///////////////////////////////////////////////////////////////////////////
138 template <typename Iterator, typename Parser, typename Skipper, typename Attribute>
139 inline bool
140 phrase_parse(
141 Iterator const& first_
142 , Iterator last
143 , Parser const& p
144 , Skipper const& s
145 , Attribute& attr
146 , skip_flag post_skip = skip_flag::post_skip)
147 {
148 Iterator first = first_;
149 return phrase_parse_main(first, last, p, s, attr, post_skip);
150 }
151
152 ///////////////////////////////////////////////////////////////////////////
153 template <typename Iterator, typename Parser, typename Skipper>
154 inline bool
155 phrase_parse(
156 Iterator& first
157 , Iterator last
158 , Parser const& p
159 , Skipper const& s
160 , skip_flag post_skip = skip_flag::post_skip)
161 {
162 return phrase_parse_main(first, last, p, s, unused, post_skip);
163 }
164
165 ///////////////////////////////////////////////////////////////////////////
166 template <typename Iterator, typename Parser, typename Skipper>
167 inline bool
168 phrase_parse(
169 Iterator const& first_
170 , Iterator last
171 , Parser const& p
172 , Skipper const& s
173 , skip_flag post_skip = skip_flag::post_skip)
174 {
175 Iterator first = first_;
176 return phrase_parse_main(first, last, p, s, unused, post_skip);
177 }
178
179 ///////////////////////////////////////////////////////////////////////////
180 template <typename Skipper>
181 struct phrase_parse_context
182 {
183 typedef decltype(
184 make_context<skipper_tag>(as_parser(std::declval<Skipper>())))
185 type;
186 };
187}}}
188
189#endif