Chris@16
|
1 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 // detail/dynamic/parser_traits.hpp
|
Chris@16
|
3 //
|
Chris@16
|
4 // Copyright 2008 Eric Niebler. Distributed under the Boost
|
Chris@16
|
5 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
7
|
Chris@16
|
8 #ifndef BOOST_XPRESSIVE_DETAIL_DYNAMIC_PARSER_TRAITS_HPP_EAN_10_04_2005
|
Chris@16
|
9 #define BOOST_XPRESSIVE_DETAIL_DYNAMIC_PARSER_TRAITS_HPP_EAN_10_04_2005
|
Chris@16
|
10
|
Chris@16
|
11 // MS compatible compilers support #pragma once
|
Chris@101
|
12 #if defined(_MSC_VER)
|
Chris@16
|
13 # pragma once
|
Chris@16
|
14 #endif
|
Chris@16
|
15
|
Chris@16
|
16 #include <string>
|
Chris@16
|
17 #include <climits>
|
Chris@16
|
18 #include <boost/config.hpp>
|
Chris@16
|
19 #include <boost/assert.hpp>
|
Chris@16
|
20 #include <boost/throw_exception.hpp>
|
Chris@16
|
21 #include <boost/xpressive/regex_error.hpp>
|
Chris@16
|
22 #include <boost/xpressive/regex_traits.hpp>
|
Chris@16
|
23 #include <boost/xpressive/detail/detail_fwd.hpp>
|
Chris@16
|
24 #include <boost/xpressive/detail/dynamic/matchable.hpp>
|
Chris@16
|
25 #include <boost/xpressive/detail/dynamic/parser_enum.hpp>
|
Chris@16
|
26 #include <boost/xpressive/detail/utility/literals.hpp>
|
Chris@16
|
27 #include <boost/xpressive/detail/utility/algorithm.hpp>
|
Chris@16
|
28
|
Chris@16
|
29 namespace boost { namespace xpressive
|
Chris@16
|
30 {
|
Chris@16
|
31
|
Chris@16
|
32 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
33 // compiler_traits
|
Chris@16
|
34 // this works for char and wchar_t. it must be specialized for anything else.
|
Chris@16
|
35 //
|
Chris@16
|
36 template<typename RegexTraits>
|
Chris@16
|
37 struct compiler_traits
|
Chris@16
|
38 {
|
Chris@16
|
39 typedef RegexTraits regex_traits;
|
Chris@16
|
40 typedef typename regex_traits::char_type char_type;
|
Chris@16
|
41 typedef typename regex_traits::string_type string_type;
|
Chris@16
|
42 typedef typename regex_traits::locale_type locale_type;
|
Chris@16
|
43
|
Chris@16
|
44 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
45 // constructor
|
Chris@16
|
46 explicit compiler_traits(RegexTraits const &traits = RegexTraits())
|
Chris@16
|
47 : traits_(traits)
|
Chris@16
|
48 , flags_(regex_constants::ECMAScript)
|
Chris@16
|
49 , space_(lookup_classname(traits_, "space"))
|
Chris@16
|
50 , alnum_(lookup_classname(traits_, "alnum"))
|
Chris@16
|
51 {
|
Chris@16
|
52 }
|
Chris@16
|
53
|
Chris@16
|
54 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
55 // flags
|
Chris@16
|
56 regex_constants::syntax_option_type flags() const
|
Chris@16
|
57 {
|
Chris@16
|
58 return this->flags_;
|
Chris@16
|
59 }
|
Chris@16
|
60
|
Chris@16
|
61 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
62 // flags
|
Chris@16
|
63 void flags(regex_constants::syntax_option_type flags)
|
Chris@16
|
64 {
|
Chris@16
|
65 this->flags_ = flags;
|
Chris@16
|
66 }
|
Chris@16
|
67
|
Chris@16
|
68 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
69 // traits
|
Chris@16
|
70 regex_traits &traits()
|
Chris@16
|
71 {
|
Chris@16
|
72 return this->traits_;
|
Chris@16
|
73 }
|
Chris@16
|
74
|
Chris@16
|
75 regex_traits const &traits() const
|
Chris@16
|
76 {
|
Chris@16
|
77 return this->traits_;
|
Chris@16
|
78 }
|
Chris@16
|
79
|
Chris@16
|
80 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
81 // imbue
|
Chris@16
|
82 locale_type imbue(locale_type const &loc)
|
Chris@16
|
83 {
|
Chris@16
|
84 locale_type oldloc = this->traits().imbue(loc);
|
Chris@16
|
85 this->space_ = lookup_classname(this->traits(), "space");
|
Chris@16
|
86 this->alnum_ = lookup_classname(this->traits(), "alnum");
|
Chris@16
|
87 return oldloc;
|
Chris@16
|
88 }
|
Chris@16
|
89
|
Chris@16
|
90 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
91 // getloc
|
Chris@16
|
92 locale_type getloc() const
|
Chris@16
|
93 {
|
Chris@16
|
94 return this->traits().getloc();
|
Chris@16
|
95 }
|
Chris@16
|
96
|
Chris@16
|
97 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
98 // get_token
|
Chris@16
|
99 // get a token and advance the iterator
|
Chris@16
|
100 template<typename FwdIter>
|
Chris@16
|
101 regex_constants::compiler_token_type get_token(FwdIter &begin, FwdIter end)
|
Chris@16
|
102 {
|
Chris@16
|
103 using namespace regex_constants;
|
Chris@16
|
104 if(this->eat_ws_(begin, end) == end)
|
Chris@16
|
105 {
|
Chris@16
|
106 return regex_constants::token_end_of_pattern;
|
Chris@16
|
107 }
|
Chris@16
|
108
|
Chris@16
|
109 switch(*begin)
|
Chris@16
|
110 {
|
Chris@16
|
111 case BOOST_XPR_CHAR_(char_type, '\\'): return this->get_escape_token(++begin, end);
|
Chris@16
|
112 case BOOST_XPR_CHAR_(char_type, '.'): ++begin; return token_any;
|
Chris@16
|
113 case BOOST_XPR_CHAR_(char_type, '^'): ++begin; return token_assert_begin_line;
|
Chris@16
|
114 case BOOST_XPR_CHAR_(char_type, '$'): ++begin; return token_assert_end_line;
|
Chris@16
|
115 case BOOST_XPR_CHAR_(char_type, '('): ++begin; return token_group_begin;
|
Chris@16
|
116 case BOOST_XPR_CHAR_(char_type, ')'): ++begin; return token_group_end;
|
Chris@16
|
117 case BOOST_XPR_CHAR_(char_type, '|'): ++begin; return token_alternate;
|
Chris@16
|
118 case BOOST_XPR_CHAR_(char_type, '['): ++begin; return token_charset_begin;
|
Chris@16
|
119
|
Chris@16
|
120 case BOOST_XPR_CHAR_(char_type, '*'):
|
Chris@16
|
121 case BOOST_XPR_CHAR_(char_type, '+'):
|
Chris@16
|
122 case BOOST_XPR_CHAR_(char_type, '?'):
|
Chris@16
|
123 return token_invalid_quantifier;
|
Chris@16
|
124
|
Chris@16
|
125 case BOOST_XPR_CHAR_(char_type, ']'):
|
Chris@16
|
126 case BOOST_XPR_CHAR_(char_type, '{'):
|
Chris@16
|
127 default:
|
Chris@16
|
128 return token_literal;
|
Chris@16
|
129 }
|
Chris@16
|
130 }
|
Chris@16
|
131
|
Chris@16
|
132 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
133 // get_quant_spec
|
Chris@16
|
134 template<typename FwdIter>
|
Chris@16
|
135 bool get_quant_spec(FwdIter &begin, FwdIter end, detail::quant_spec &spec)
|
Chris@16
|
136 {
|
Chris@16
|
137 using namespace regex_constants;
|
Chris@16
|
138 FwdIter old_begin;
|
Chris@16
|
139
|
Chris@16
|
140 if(this->eat_ws_(begin, end) == end)
|
Chris@16
|
141 {
|
Chris@16
|
142 return false;
|
Chris@16
|
143 }
|
Chris@16
|
144
|
Chris@16
|
145 switch(*begin)
|
Chris@16
|
146 {
|
Chris@16
|
147 case BOOST_XPR_CHAR_(char_type, '*'):
|
Chris@16
|
148 spec.min_ = 0;
|
Chris@16
|
149 spec.max_ = (std::numeric_limits<unsigned int>::max)();
|
Chris@16
|
150 break;
|
Chris@16
|
151
|
Chris@16
|
152 case BOOST_XPR_CHAR_(char_type, '+'):
|
Chris@16
|
153 spec.min_ = 1;
|
Chris@16
|
154 spec.max_ = (std::numeric_limits<unsigned int>::max)();
|
Chris@16
|
155 break;
|
Chris@16
|
156
|
Chris@16
|
157 case BOOST_XPR_CHAR_(char_type, '?'):
|
Chris@16
|
158 spec.min_ = 0;
|
Chris@16
|
159 spec.max_ = 1;
|
Chris@16
|
160 break;
|
Chris@16
|
161
|
Chris@16
|
162 case BOOST_XPR_CHAR_(char_type, '{'):
|
Chris@16
|
163 old_begin = this->eat_ws_(++begin, end);
|
Chris@16
|
164 spec.min_ = spec.max_ = detail::toi(begin, end, this->traits());
|
Chris@16
|
165 BOOST_XPR_ENSURE_
|
Chris@16
|
166 (
|
Chris@16
|
167 begin != old_begin && begin != end, error_brace, "invalid quantifier"
|
Chris@16
|
168 );
|
Chris@16
|
169
|
Chris@16
|
170 if(*begin == BOOST_XPR_CHAR_(char_type, ','))
|
Chris@16
|
171 {
|
Chris@16
|
172 old_begin = this->eat_ws_(++begin, end);
|
Chris@16
|
173 spec.max_ = detail::toi(begin, end, this->traits());
|
Chris@16
|
174 BOOST_XPR_ENSURE_
|
Chris@16
|
175 (
|
Chris@16
|
176 begin != end && BOOST_XPR_CHAR_(char_type, '}') == *begin
|
Chris@16
|
177 , error_brace, "invalid quantifier"
|
Chris@16
|
178 );
|
Chris@16
|
179
|
Chris@16
|
180 if(begin == old_begin)
|
Chris@16
|
181 {
|
Chris@16
|
182 spec.max_ = (std::numeric_limits<unsigned int>::max)();
|
Chris@16
|
183 }
|
Chris@16
|
184 else
|
Chris@16
|
185 {
|
Chris@16
|
186 BOOST_XPR_ENSURE_
|
Chris@16
|
187 (
|
Chris@16
|
188 spec.min_ <= spec.max_, error_badbrace, "invalid quantification range"
|
Chris@16
|
189 );
|
Chris@16
|
190 }
|
Chris@16
|
191 }
|
Chris@16
|
192 else
|
Chris@16
|
193 {
|
Chris@16
|
194 BOOST_XPR_ENSURE_
|
Chris@16
|
195 (
|
Chris@16
|
196 BOOST_XPR_CHAR_(char_type, '}') == *begin, error_brace, "invalid quantifier"
|
Chris@16
|
197 );
|
Chris@16
|
198 }
|
Chris@16
|
199 break;
|
Chris@16
|
200
|
Chris@16
|
201 default:
|
Chris@16
|
202 return false;
|
Chris@16
|
203 }
|
Chris@16
|
204
|
Chris@16
|
205 spec.greedy_ = true;
|
Chris@16
|
206 if(this->eat_ws_(++begin, end) != end && BOOST_XPR_CHAR_(char_type, '?') == *begin)
|
Chris@16
|
207 {
|
Chris@16
|
208 ++begin;
|
Chris@16
|
209 spec.greedy_ = false;
|
Chris@16
|
210 }
|
Chris@16
|
211
|
Chris@16
|
212 return true;
|
Chris@16
|
213 }
|
Chris@16
|
214
|
Chris@16
|
215 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
216 // get_group_type
|
Chris@16
|
217 template<typename FwdIter>
|
Chris@16
|
218 regex_constants::compiler_token_type get_group_type(FwdIter &begin, FwdIter end, string_type &name)
|
Chris@16
|
219 {
|
Chris@16
|
220 using namespace regex_constants;
|
Chris@16
|
221 if(this->eat_ws_(begin, end) != end && BOOST_XPR_CHAR_(char_type, '?') == *begin)
|
Chris@16
|
222 {
|
Chris@16
|
223 this->eat_ws_(++begin, end);
|
Chris@16
|
224 BOOST_XPR_ENSURE_(begin != end, error_paren, "incomplete extension");
|
Chris@16
|
225
|
Chris@16
|
226 switch(*begin)
|
Chris@16
|
227 {
|
Chris@16
|
228 case BOOST_XPR_CHAR_(char_type, ':'): ++begin; return token_no_mark;
|
Chris@16
|
229 case BOOST_XPR_CHAR_(char_type, '>'): ++begin; return token_independent_sub_expression;
|
Chris@16
|
230 case BOOST_XPR_CHAR_(char_type, '#'): ++begin; return token_comment;
|
Chris@16
|
231 case BOOST_XPR_CHAR_(char_type, '='): ++begin; return token_positive_lookahead;
|
Chris@16
|
232 case BOOST_XPR_CHAR_(char_type, '!'): ++begin; return token_negative_lookahead;
|
Chris@16
|
233 case BOOST_XPR_CHAR_(char_type, 'R'): ++begin; return token_recurse;
|
Chris@16
|
234 case BOOST_XPR_CHAR_(char_type, '$'):
|
Chris@16
|
235 this->get_name_(++begin, end, name);
|
Chris@16
|
236 BOOST_XPR_ENSURE_(begin != end, error_paren, "incomplete extension");
|
Chris@16
|
237 if(BOOST_XPR_CHAR_(char_type, '=') == *begin)
|
Chris@16
|
238 {
|
Chris@16
|
239 ++begin;
|
Chris@16
|
240 return token_rule_assign;
|
Chris@16
|
241 }
|
Chris@16
|
242 return token_rule_ref;
|
Chris@16
|
243
|
Chris@16
|
244 case BOOST_XPR_CHAR_(char_type, '<'):
|
Chris@16
|
245 this->eat_ws_(++begin, end);
|
Chris@16
|
246 BOOST_XPR_ENSURE_(begin != end, error_paren, "incomplete extension");
|
Chris@16
|
247 switch(*begin)
|
Chris@16
|
248 {
|
Chris@16
|
249 case BOOST_XPR_CHAR_(char_type, '='): ++begin; return token_positive_lookbehind;
|
Chris@16
|
250 case BOOST_XPR_CHAR_(char_type, '!'): ++begin; return token_negative_lookbehind;
|
Chris@16
|
251 default:
|
Chris@16
|
252 BOOST_THROW_EXCEPTION(regex_error(error_badbrace, "unrecognized extension"));
|
Chris@16
|
253 }
|
Chris@16
|
254
|
Chris@16
|
255 case BOOST_XPR_CHAR_(char_type, 'P'):
|
Chris@16
|
256 this->eat_ws_(++begin, end);
|
Chris@16
|
257 BOOST_XPR_ENSURE_(begin != end, error_paren, "incomplete extension");
|
Chris@16
|
258 switch(*begin)
|
Chris@16
|
259 {
|
Chris@16
|
260 case BOOST_XPR_CHAR_(char_type, '<'):
|
Chris@16
|
261 this->get_name_(++begin, end, name);
|
Chris@16
|
262 BOOST_XPR_ENSURE_(begin != end && BOOST_XPR_CHAR_(char_type, '>') == *begin++, error_paren, "incomplete extension");
|
Chris@16
|
263 return token_named_mark;
|
Chris@16
|
264 case BOOST_XPR_CHAR_(char_type, '='):
|
Chris@16
|
265 this->get_name_(++begin, end, name);
|
Chris@16
|
266 BOOST_XPR_ENSURE_(begin != end, error_paren, "incomplete extension");
|
Chris@16
|
267 return token_named_mark_ref;
|
Chris@16
|
268 default:
|
Chris@16
|
269 BOOST_THROW_EXCEPTION(regex_error(error_badbrace, "unrecognized extension"));
|
Chris@16
|
270 }
|
Chris@16
|
271
|
Chris@16
|
272 case BOOST_XPR_CHAR_(char_type, 'i'):
|
Chris@16
|
273 case BOOST_XPR_CHAR_(char_type, 'm'):
|
Chris@16
|
274 case BOOST_XPR_CHAR_(char_type, 's'):
|
Chris@16
|
275 case BOOST_XPR_CHAR_(char_type, 'x'):
|
Chris@16
|
276 case BOOST_XPR_CHAR_(char_type, '-'):
|
Chris@16
|
277 return this->parse_mods_(begin, end);
|
Chris@16
|
278
|
Chris@16
|
279 default:
|
Chris@16
|
280 BOOST_THROW_EXCEPTION(regex_error(error_badbrace, "unrecognized extension"));
|
Chris@16
|
281 }
|
Chris@16
|
282 }
|
Chris@16
|
283
|
Chris@16
|
284 return token_literal;
|
Chris@16
|
285 }
|
Chris@16
|
286
|
Chris@16
|
287 //////////////////////////////////////////////////////////////////////////
|
Chris@16
|
288 // get_charset_token
|
Chris@16
|
289 // NOTE: white-space is *never* ignored in a charset.
|
Chris@16
|
290 template<typename FwdIter>
|
Chris@16
|
291 regex_constants::compiler_token_type get_charset_token(FwdIter &begin, FwdIter end)
|
Chris@16
|
292 {
|
Chris@16
|
293 using namespace regex_constants;
|
Chris@16
|
294 BOOST_ASSERT(begin != end);
|
Chris@16
|
295 switch(*begin)
|
Chris@16
|
296 {
|
Chris@16
|
297 case BOOST_XPR_CHAR_(char_type, '^'): ++begin; return token_charset_invert;
|
Chris@16
|
298 case BOOST_XPR_CHAR_(char_type, '-'): ++begin; return token_charset_hyphen;
|
Chris@16
|
299 case BOOST_XPR_CHAR_(char_type, ']'): ++begin; return token_charset_end;
|
Chris@16
|
300 case BOOST_XPR_CHAR_(char_type, '['):
|
Chris@16
|
301 {
|
Chris@16
|
302 FwdIter next = begin; ++next;
|
Chris@16
|
303 if(next != end)
|
Chris@16
|
304 {
|
Chris@16
|
305 BOOST_XPR_ENSURE_(
|
Chris@16
|
306 *next != BOOST_XPR_CHAR_(char_type, '=')
|
Chris@16
|
307 , error_collate
|
Chris@16
|
308 , "equivalence classes are not yet supported"
|
Chris@16
|
309 );
|
Chris@16
|
310
|
Chris@16
|
311 BOOST_XPR_ENSURE_(
|
Chris@16
|
312 *next != BOOST_XPR_CHAR_(char_type, '.')
|
Chris@16
|
313 , error_collate
|
Chris@16
|
314 , "collation sequences are not yet supported"
|
Chris@16
|
315 );
|
Chris@16
|
316
|
Chris@16
|
317 if(*next == BOOST_XPR_CHAR_(char_type, ':'))
|
Chris@16
|
318 {
|
Chris@16
|
319 begin = ++next;
|
Chris@16
|
320 return token_posix_charset_begin;
|
Chris@16
|
321 }
|
Chris@16
|
322 }
|
Chris@16
|
323 }
|
Chris@16
|
324 break;
|
Chris@16
|
325 case BOOST_XPR_CHAR_(char_type, ':'):
|
Chris@16
|
326 {
|
Chris@16
|
327 FwdIter next = begin; ++next;
|
Chris@16
|
328 if(next != end && *next == BOOST_XPR_CHAR_(char_type, ']'))
|
Chris@16
|
329 {
|
Chris@16
|
330 begin = ++next;
|
Chris@16
|
331 return token_posix_charset_end;
|
Chris@16
|
332 }
|
Chris@16
|
333 }
|
Chris@16
|
334 break;
|
Chris@16
|
335 case BOOST_XPR_CHAR_(char_type, '\\'):
|
Chris@16
|
336 if(++begin != end)
|
Chris@16
|
337 {
|
Chris@16
|
338 switch(*begin)
|
Chris@16
|
339 {
|
Chris@16
|
340 case BOOST_XPR_CHAR_(char_type, 'b'): ++begin; return token_charset_backspace;
|
Chris@16
|
341 default:;
|
Chris@16
|
342 }
|
Chris@16
|
343 }
|
Chris@16
|
344 return token_escape;
|
Chris@16
|
345 default:;
|
Chris@16
|
346 }
|
Chris@16
|
347 return token_literal;
|
Chris@16
|
348 }
|
Chris@16
|
349
|
Chris@16
|
350 //////////////////////////////////////////////////////////////////////////
|
Chris@16
|
351 // get_escape_token
|
Chris@16
|
352 template<typename FwdIter>
|
Chris@16
|
353 regex_constants::compiler_token_type get_escape_token(FwdIter &begin, FwdIter end)
|
Chris@16
|
354 {
|
Chris@16
|
355 using namespace regex_constants;
|
Chris@16
|
356 if(begin != end)
|
Chris@16
|
357 {
|
Chris@16
|
358 switch(*begin)
|
Chris@16
|
359 {
|
Chris@16
|
360 //case BOOST_XPR_CHAR_(char_type, 'a'): ++begin; return token_escape_bell;
|
Chris@16
|
361 //case BOOST_XPR_CHAR_(char_type, 'c'): ++begin; return token_escape_control;
|
Chris@16
|
362 //case BOOST_XPR_CHAR_(char_type, 'e'): ++begin; return token_escape_escape;
|
Chris@16
|
363 //case BOOST_XPR_CHAR_(char_type, 'f'): ++begin; return token_escape_formfeed;
|
Chris@16
|
364 //case BOOST_XPR_CHAR_(char_type, 'n'): ++begin; return token_escape_newline;
|
Chris@16
|
365 //case BOOST_XPR_CHAR_(char_type, 't'): ++begin; return token_escape_horizontal_tab;
|
Chris@16
|
366 //case BOOST_XPR_CHAR_(char_type, 'v'): ++begin; return token_escape_vertical_tab;
|
Chris@16
|
367 case BOOST_XPR_CHAR_(char_type, 'A'): ++begin; return token_assert_begin_sequence;
|
Chris@16
|
368 case BOOST_XPR_CHAR_(char_type, 'b'): ++begin; return token_assert_word_boundary;
|
Chris@16
|
369 case BOOST_XPR_CHAR_(char_type, 'B'): ++begin; return token_assert_not_word_boundary;
|
Chris@16
|
370 case BOOST_XPR_CHAR_(char_type, 'E'): ++begin; return token_quote_meta_end;
|
Chris@16
|
371 case BOOST_XPR_CHAR_(char_type, 'Q'): ++begin; return token_quote_meta_begin;
|
Chris@16
|
372 case BOOST_XPR_CHAR_(char_type, 'Z'): ++begin; return token_assert_end_sequence;
|
Chris@16
|
373 // Non-standard extension to ECMAScript syntax
|
Chris@16
|
374 case BOOST_XPR_CHAR_(char_type, '<'): ++begin; return token_assert_word_begin;
|
Chris@16
|
375 case BOOST_XPR_CHAR_(char_type, '>'): ++begin; return token_assert_word_end;
|
Chris@16
|
376 default:; // fall-through
|
Chris@16
|
377 }
|
Chris@16
|
378 }
|
Chris@16
|
379
|
Chris@16
|
380 return token_escape;
|
Chris@16
|
381 }
|
Chris@16
|
382
|
Chris@16
|
383 private:
|
Chris@16
|
384
|
Chris@16
|
385 //////////////////////////////////////////////////////////////////////////
|
Chris@16
|
386 // parse_mods_
|
Chris@16
|
387 template<typename FwdIter>
|
Chris@16
|
388 regex_constants::compiler_token_type parse_mods_(FwdIter &begin, FwdIter end)
|
Chris@16
|
389 {
|
Chris@16
|
390 using namespace regex_constants;
|
Chris@16
|
391 bool set = true;
|
Chris@16
|
392 do switch(*begin)
|
Chris@16
|
393 {
|
Chris@16
|
394 case BOOST_XPR_CHAR_(char_type, 'i'): this->flag_(set, icase_); break;
|
Chris@16
|
395 case BOOST_XPR_CHAR_(char_type, 'm'): this->flag_(!set, single_line); break;
|
Chris@16
|
396 case BOOST_XPR_CHAR_(char_type, 's'): this->flag_(!set, not_dot_newline); break;
|
Chris@16
|
397 case BOOST_XPR_CHAR_(char_type, 'x'): this->flag_(set, ignore_white_space); break;
|
Chris@16
|
398 case BOOST_XPR_CHAR_(char_type, ':'): ++begin; BOOST_FALLTHROUGH;
|
Chris@16
|
399 case BOOST_XPR_CHAR_(char_type, ')'): return token_no_mark;
|
Chris@16
|
400 case BOOST_XPR_CHAR_(char_type, '-'): if(false == (set = !set)) break; BOOST_FALLTHROUGH;
|
Chris@16
|
401 default: BOOST_THROW_EXCEPTION(regex_error(error_paren, "unknown pattern modifier"));
|
Chris@16
|
402 }
|
Chris@16
|
403 while(BOOST_XPR_ENSURE_(++begin != end, error_paren, "incomplete extension"));
|
Chris@16
|
404 // this return is technically unreachable, but this must
|
Chris@16
|
405 // be here to work around a bug in gcc 4.0
|
Chris@16
|
406 return token_no_mark;
|
Chris@16
|
407 }
|
Chris@16
|
408
|
Chris@16
|
409 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
410 // flag_
|
Chris@16
|
411 void flag_(bool set, regex_constants::syntax_option_type flag)
|
Chris@16
|
412 {
|
Chris@16
|
413 this->flags_ = set ? (this->flags_ | flag) : (this->flags_ & ~flag);
|
Chris@16
|
414 }
|
Chris@16
|
415
|
Chris@16
|
416 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
417 // is_space_
|
Chris@16
|
418 bool is_space_(char_type ch) const
|
Chris@16
|
419 {
|
Chris@16
|
420 return 0 != this->space_ && this->traits().isctype(ch, this->space_);
|
Chris@16
|
421 }
|
Chris@16
|
422
|
Chris@16
|
423 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
424 // is_alnum_
|
Chris@16
|
425 bool is_alnum_(char_type ch) const
|
Chris@16
|
426 {
|
Chris@16
|
427 return 0 != this->alnum_ && this->traits().isctype(ch, this->alnum_);
|
Chris@16
|
428 }
|
Chris@16
|
429
|
Chris@16
|
430 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
431 // get_name_
|
Chris@16
|
432 template<typename FwdIter>
|
Chris@16
|
433 void get_name_(FwdIter &begin, FwdIter end, string_type &name)
|
Chris@16
|
434 {
|
Chris@16
|
435 this->eat_ws_(begin, end);
|
Chris@16
|
436 for(name.clear(); begin != end && this->is_alnum_(*begin); ++begin)
|
Chris@16
|
437 {
|
Chris@16
|
438 name.push_back(*begin);
|
Chris@16
|
439 }
|
Chris@16
|
440 this->eat_ws_(begin, end);
|
Chris@16
|
441 BOOST_XPR_ENSURE_(!name.empty(), regex_constants::error_paren, "incomplete extension");
|
Chris@16
|
442 }
|
Chris@16
|
443
|
Chris@16
|
444 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
445 // eat_ws_
|
Chris@16
|
446 template<typename FwdIter>
|
Chris@16
|
447 FwdIter &eat_ws_(FwdIter &begin, FwdIter end)
|
Chris@16
|
448 {
|
Chris@16
|
449 if(0 != (regex_constants::ignore_white_space & this->flags()))
|
Chris@16
|
450 {
|
Chris@16
|
451 while(end != begin && (BOOST_XPR_CHAR_(char_type, '#') == *begin || this->is_space_(*begin)))
|
Chris@16
|
452 {
|
Chris@16
|
453 if(BOOST_XPR_CHAR_(char_type, '#') == *begin++)
|
Chris@16
|
454 {
|
Chris@16
|
455 while(end != begin && BOOST_XPR_CHAR_(char_type, '\n') != *begin++) {}
|
Chris@16
|
456 }
|
Chris@16
|
457 else
|
Chris@16
|
458 {
|
Chris@16
|
459 for(; end != begin && this->is_space_(*begin); ++begin) {}
|
Chris@16
|
460 }
|
Chris@16
|
461 }
|
Chris@16
|
462 }
|
Chris@16
|
463
|
Chris@16
|
464 return begin;
|
Chris@16
|
465 }
|
Chris@16
|
466
|
Chris@16
|
467 regex_traits traits_;
|
Chris@16
|
468 regex_constants::syntax_option_type flags_;
|
Chris@16
|
469 typename regex_traits::char_class_type space_;
|
Chris@16
|
470 typename regex_traits::char_class_type alnum_;
|
Chris@16
|
471 };
|
Chris@16
|
472
|
Chris@16
|
473 }} // namespace boost::xpressive
|
Chris@16
|
474
|
Chris@16
|
475 #endif
|