600
|
1 |
/*
|
|
2 |
*
|
|
3 |
* Copyright (c) 2004
|
|
4 |
* John Maddock
|
|
5 |
*
|
|
6 |
* Use, modification and distribution are subject to the
|
|
7 |
* Boost Software License, Version 1.0. (See accompanying file
|
|
8 |
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
9 |
*
|
|
10 |
*/
|
|
11 |
|
|
12 |
/*
|
|
13 |
* LOCATION: see http://www.boost.org for most recent version.
|
|
14 |
* FILE basic_regex_parser.cpp
|
|
15 |
* VERSION see <boost/version.hpp>
|
|
16 |
* DESCRIPTION: Declares template class basic_regex_parser.
|
|
17 |
*/
|
|
18 |
|
|
19 |
#ifndef BOOST_REGEX_V4_BASIC_REGEX_PARSER_HPP
|
|
20 |
#define BOOST_REGEX_V4_BASIC_REGEX_PARSER_HPP
|
|
21 |
|
|
22 |
#ifdef BOOST_MSVC
|
|
23 |
#pragma warning(push)
|
|
24 |
#pragma warning(disable: 4103)
|
|
25 |
#endif
|
|
26 |
#ifdef BOOST_HAS_ABI_HEADERS
|
|
27 |
# include BOOST_ABI_PREFIX
|
|
28 |
#endif
|
|
29 |
#ifdef BOOST_MSVC
|
|
30 |
#pragma warning(pop)
|
|
31 |
#endif
|
|
32 |
|
|
33 |
namespace boost{
|
|
34 |
namespace re_detail{
|
|
35 |
|
|
36 |
#ifdef BOOST_MSVC
|
|
37 |
#pragma warning(push)
|
|
38 |
#pragma warning(disable:4244 4800)
|
|
39 |
#endif
|
|
40 |
|
|
41 |
template <class charT, class traits>
|
|
42 |
class basic_regex_parser : public basic_regex_creator<charT, traits>
|
|
43 |
{
|
|
44 |
public:
|
|
45 |
basic_regex_parser(regex_data<charT, traits>* data);
|
|
46 |
void parse(const charT* p1, const charT* p2, unsigned flags);
|
|
47 |
void fail(regex_constants::error_type error_code, std::ptrdiff_t position);
|
|
48 |
|
|
49 |
bool parse_all();
|
|
50 |
bool parse_basic();
|
|
51 |
bool parse_extended();
|
|
52 |
bool parse_literal();
|
|
53 |
bool parse_open_paren();
|
|
54 |
bool parse_basic_escape();
|
|
55 |
bool parse_extended_escape();
|
|
56 |
bool parse_match_any();
|
|
57 |
bool parse_repeat(std::size_t low = 0, std::size_t high = (std::numeric_limits<std::size_t>::max)());
|
|
58 |
bool parse_repeat_range(bool isbasic);
|
|
59 |
bool parse_alt();
|
|
60 |
bool parse_set();
|
|
61 |
bool parse_backref();
|
|
62 |
void parse_set_literal(basic_char_set<charT, traits>& char_set);
|
|
63 |
bool parse_inner_set(basic_char_set<charT, traits>& char_set);
|
|
64 |
bool parse_QE();
|
|
65 |
bool parse_perl_extension();
|
|
66 |
bool add_emacs_code(bool negate);
|
|
67 |
bool unwind_alts(std::ptrdiff_t last_paren_start);
|
|
68 |
digraph<charT> get_next_set_literal(basic_char_set<charT, traits>& char_set);
|
|
69 |
charT unescape_character();
|
|
70 |
regex_constants::syntax_option_type parse_options();
|
|
71 |
|
|
72 |
private:
|
|
73 |
typedef bool (basic_regex_parser::*parser_proc_type)();
|
|
74 |
typedef typename traits::string_type string_type;
|
|
75 |
typedef typename traits::char_class_type char_class_type;
|
|
76 |
parser_proc_type m_parser_proc; // the main parser to use
|
|
77 |
const charT* m_base; // the start of the string being parsed
|
|
78 |
const charT* m_end; // the end of the string being parsed
|
|
79 |
const charT* m_position; // our current parser position
|
|
80 |
unsigned m_mark_count; // how many sub-expressions we have
|
|
81 |
std::ptrdiff_t m_paren_start; // where the last seen ')' began (where repeats are inserted).
|
|
82 |
std::ptrdiff_t m_alt_insert_point; // where to insert the next alternative
|
|
83 |
bool m_has_case_change; // true if somewhere in the current block the case has changed
|
|
84 |
#if defined(BOOST_MSVC) && defined(_M_IX86)
|
|
85 |
// This is an ugly warning suppression workaround (for warnings *inside* std::vector
|
|
86 |
// that can not otherwise be suppressed)...
|
|
87 |
BOOST_STATIC_ASSERT(sizeof(long) >= sizeof(void*));
|
|
88 |
std::vector<long> m_alt_jumps; // list of alternative in the current scope.
|
|
89 |
#else
|
|
90 |
std::vector<std::ptrdiff_t> m_alt_jumps; // list of alternative in the current scope.
|
|
91 |
#endif
|
|
92 |
|
|
93 |
basic_regex_parser& operator=(const basic_regex_parser&);
|
|
94 |
basic_regex_parser(const basic_regex_parser&);
|
|
95 |
};
|
|
96 |
|
|
97 |
template <class charT, class traits>
|
|
98 |
basic_regex_parser<charT, traits>::basic_regex_parser(regex_data<charT, traits>* data)
|
|
99 |
: basic_regex_creator<charT, traits>(data), m_mark_count(0), m_paren_start(0), m_alt_insert_point(0), m_has_case_change(false)
|
|
100 |
{
|
|
101 |
}
|
|
102 |
|
|
103 |
template <class charT, class traits>
|
|
104 |
void basic_regex_parser<charT, traits>::parse(const charT* p1, const charT* p2, unsigned l_flags)
|
|
105 |
{
|
|
106 |
// pass l_flags on to base class:
|
|
107 |
this->init(l_flags);
|
|
108 |
// set up pointers:
|
|
109 |
m_position = m_base = p1;
|
|
110 |
m_end = p2;
|
|
111 |
// empty strings are errors:
|
|
112 |
if((p1 == p2) &&
|
|
113 |
(
|
|
114 |
((l_flags & regbase::main_option_type) != regbase::perl_syntax_group)
|
|
115 |
|| (l_flags & regbase::no_empty_expressions)
|
|
116 |
)
|
|
117 |
)
|
|
118 |
{
|
|
119 |
fail(regex_constants::error_empty, 0);
|
|
120 |
return;
|
|
121 |
}
|
|
122 |
// select which parser to use:
|
|
123 |
switch(l_flags & regbase::main_option_type)
|
|
124 |
{
|
|
125 |
case regbase::perl_syntax_group:
|
|
126 |
m_parser_proc = &basic_regex_parser<charT, traits>::parse_extended;
|
|
127 |
break;
|
|
128 |
case regbase::basic_syntax_group:
|
|
129 |
m_parser_proc = &basic_regex_parser<charT, traits>::parse_basic;
|
|
130 |
break;
|
|
131 |
case regbase::literal:
|
|
132 |
m_parser_proc = &basic_regex_parser<charT, traits>::parse_literal;
|
|
133 |
break;
|
|
134 |
}
|
|
135 |
|
|
136 |
// parse all our characters:
|
|
137 |
bool result = parse_all();
|
|
138 |
//
|
|
139 |
// Unwind our alternatives:
|
|
140 |
//
|
|
141 |
unwind_alts(-1);
|
|
142 |
// reset l_flags as a global scope (?imsx) may have altered them:
|
|
143 |
this->flags(l_flags);
|
|
144 |
// if we haven't gobbled up all the characters then we must
|
|
145 |
// have had an unexpected ')' :
|
|
146 |
if(!result)
|
|
147 |
{
|
|
148 |
fail(regex_constants::error_paren, ::boost::re_detail::distance(m_base, m_position));
|
|
149 |
return;
|
|
150 |
}
|
|
151 |
// if an error has been set then give up now:
|
|
152 |
if(this->m_pdata->m_status)
|
|
153 |
return;
|
|
154 |
// fill in our sub-expression count:
|
|
155 |
this->m_pdata->m_mark_count = 1 + m_mark_count;
|
|
156 |
this->finalize(p1, p2);
|
|
157 |
}
|
|
158 |
|
|
159 |
template <class charT, class traits>
|
|
160 |
void basic_regex_parser<charT, traits>::fail(regex_constants::error_type error_code, std::ptrdiff_t position)
|
|
161 |
{
|
|
162 |
if(0 == this->m_pdata->m_status) // update the error code if not already set
|
|
163 |
this->m_pdata->m_status = error_code;
|
|
164 |
m_position = m_end; // don't bother parsing anything else
|
|
165 |
// get the error message:
|
|
166 |
std::string message = this->m_pdata->m_ptraits->error_string(error_code);
|
|
167 |
// and raise the exception, this will do nothing if exceptions are disabled:
|
|
168 |
#ifndef BOOST_NO_EXCEPTIONS
|
|
169 |
if(0 == (this->flags() & regex_constants::no_except))
|
|
170 |
{
|
|
171 |
boost::regex_error e(message, error_code, position);
|
|
172 |
e.raise();
|
|
173 |
}
|
|
174 |
#else
|
|
175 |
(void)position; // suppress warnings.
|
|
176 |
#endif
|
|
177 |
}
|
|
178 |
|
|
179 |
template <class charT, class traits>
|
|
180 |
bool basic_regex_parser<charT, traits>::parse_all()
|
|
181 |
{
|
|
182 |
bool result = true;
|
|
183 |
while(result && (m_position != m_end))
|
|
184 |
{
|
|
185 |
result = (this->*m_parser_proc)();
|
|
186 |
}
|
|
187 |
return result;
|
|
188 |
}
|
|
189 |
|
|
190 |
#ifdef BOOST_MSVC
|
|
191 |
#pragma warning(push)
|
|
192 |
#pragma warning(disable:4702)
|
|
193 |
#endif
|
|
194 |
template <class charT, class traits>
|
|
195 |
bool basic_regex_parser<charT, traits>::parse_basic()
|
|
196 |
{
|
|
197 |
switch(this->m_traits.syntax_type(*m_position))
|
|
198 |
{
|
|
199 |
case regex_constants::syntax_escape:
|
|
200 |
return parse_basic_escape();
|
|
201 |
case regex_constants::syntax_dot:
|
|
202 |
return parse_match_any();
|
|
203 |
case regex_constants::syntax_caret:
|
|
204 |
++m_position;
|
|
205 |
this->append_state(syntax_element_start_line);
|
|
206 |
break;
|
|
207 |
case regex_constants::syntax_dollar:
|
|
208 |
++m_position;
|
|
209 |
this->append_state(syntax_element_end_line);
|
|
210 |
break;
|
|
211 |
case regex_constants::syntax_star:
|
|
212 |
if(!(this->m_last_state) || (this->m_last_state->type == syntax_element_start_line))
|
|
213 |
return parse_literal();
|
|
214 |
else
|
|
215 |
{
|
|
216 |
++m_position;
|
|
217 |
return parse_repeat();
|
|
218 |
}
|
|
219 |
case regex_constants::syntax_plus:
|
|
220 |
if(!(this->m_last_state) || (this->m_last_state->type == syntax_element_start_line) || !(this->flags() & regbase::emacs_ex))
|
|
221 |
return parse_literal();
|
|
222 |
else
|
|
223 |
{
|
|
224 |
++m_position;
|
|
225 |
return parse_repeat(1);
|
|
226 |
}
|
|
227 |
case regex_constants::syntax_question:
|
|
228 |
if(!(this->m_last_state) || (this->m_last_state->type == syntax_element_start_line) || !(this->flags() & regbase::emacs_ex))
|
|
229 |
return parse_literal();
|
|
230 |
else
|
|
231 |
{
|
|
232 |
++m_position;
|
|
233 |
return parse_repeat(0, 1);
|
|
234 |
}
|
|
235 |
case regex_constants::syntax_open_set:
|
|
236 |
return parse_set();
|
|
237 |
case regex_constants::syntax_newline:
|
|
238 |
if(this->flags() & regbase::newline_alt)
|
|
239 |
return parse_alt();
|
|
240 |
else
|
|
241 |
return parse_literal();
|
|
242 |
default:
|
|
243 |
return parse_literal();
|
|
244 |
}
|
|
245 |
return true;
|
|
246 |
}
|
|
247 |
|
|
248 |
template <class charT, class traits>
|
|
249 |
bool basic_regex_parser<charT, traits>::parse_extended()
|
|
250 |
{
|
|
251 |
bool result = true;
|
|
252 |
switch(this->m_traits.syntax_type(*m_position))
|
|
253 |
{
|
|
254 |
case regex_constants::syntax_open_mark:
|
|
255 |
return parse_open_paren();
|
|
256 |
case regex_constants::syntax_close_mark:
|
|
257 |
return false;
|
|
258 |
case regex_constants::syntax_escape:
|
|
259 |
return parse_extended_escape();
|
|
260 |
case regex_constants::syntax_dot:
|
|
261 |
return parse_match_any();
|
|
262 |
case regex_constants::syntax_caret:
|
|
263 |
++m_position;
|
|
264 |
this->append_state(
|
|
265 |
(this->flags() & regex_constants::no_mod_m ? syntax_element_buffer_start : syntax_element_start_line));
|
|
266 |
break;
|
|
267 |
case regex_constants::syntax_dollar:
|
|
268 |
++m_position;
|
|
269 |
this->append_state(
|
|
270 |
(this->flags() & regex_constants::no_mod_m ? syntax_element_buffer_end : syntax_element_end_line));
|
|
271 |
break;
|
|
272 |
case regex_constants::syntax_star:
|
|
273 |
if(m_position == this->m_base)
|
|
274 |
{
|
|
275 |
fail(regex_constants::error_badrepeat, 0);
|
|
276 |
return false;
|
|
277 |
}
|
|
278 |
++m_position;
|
|
279 |
return parse_repeat();
|
|
280 |
case regex_constants::syntax_question:
|
|
281 |
if(m_position == this->m_base)
|
|
282 |
{
|
|
283 |
fail(regex_constants::error_badrepeat, 0);
|
|
284 |
return false;
|
|
285 |
}
|
|
286 |
++m_position;
|
|
287 |
return parse_repeat(0,1);
|
|
288 |
case regex_constants::syntax_plus:
|
|
289 |
if(m_position == this->m_base)
|
|
290 |
{
|
|
291 |
fail(regex_constants::error_badrepeat, 0);
|
|
292 |
return false;
|
|
293 |
}
|
|
294 |
++m_position;
|
|
295 |
return parse_repeat(1);
|
|
296 |
case regex_constants::syntax_open_brace:
|
|
297 |
++m_position;
|
|
298 |
return parse_repeat_range(false);
|
|
299 |
case regex_constants::syntax_close_brace:
|
|
300 |
fail(regex_constants::error_brace, this->m_position - this->m_end);
|
|
301 |
return false;
|
|
302 |
case regex_constants::syntax_or:
|
|
303 |
return parse_alt();
|
|
304 |
case regex_constants::syntax_open_set:
|
|
305 |
return parse_set();
|
|
306 |
case regex_constants::syntax_newline:
|
|
307 |
if(this->flags() & regbase::newline_alt)
|
|
308 |
return parse_alt();
|
|
309 |
else
|
|
310 |
return parse_literal();
|
|
311 |
case regex_constants::syntax_hash:
|
|
312 |
//
|
|
313 |
// If we have a mod_x flag set, then skip until
|
|
314 |
// we get to a newline character:
|
|
315 |
//
|
|
316 |
if((this->flags()
|
|
317 |
& (regbase::no_perl_ex|regbase::mod_x))
|
|
318 |
== regbase::mod_x)
|
|
319 |
{
|
|
320 |
while((m_position != m_end) && !is_separator(*m_position++)){}
|
|
321 |
return true;
|
|
322 |
}
|
|
323 |
// Otherwise fall through:
|
|
324 |
default:
|
|
325 |
result = parse_literal();
|
|
326 |
break;
|
|
327 |
}
|
|
328 |
return result;
|
|
329 |
}
|
|
330 |
#ifdef BOOST_MSVC
|
|
331 |
#pragma warning(pop)
|
|
332 |
#endif
|
|
333 |
|
|
334 |
template <class charT, class traits>
|
|
335 |
bool basic_regex_parser<charT, traits>::parse_literal()
|
|
336 |
{
|
|
337 |
// append this as a literal provided it's not a space character
|
|
338 |
// or the perl option regbase::mod_x is not set:
|
|
339 |
if(
|
|
340 |
((this->flags()
|
|
341 |
& (regbase::main_option_type|regbase::mod_x|regbase::no_perl_ex))
|
|
342 |
!= regbase::mod_x)
|
|
343 |
|| !this->m_traits.isctype(*m_position, this->m_mask_space))
|
|
344 |
this->append_literal(*m_position);
|
|
345 |
++m_position;
|
|
346 |
return true;
|
|
347 |
}
|
|
348 |
|
|
349 |
template <class charT, class traits>
|
|
350 |
bool basic_regex_parser<charT, traits>::parse_open_paren()
|
|
351 |
{
|
|
352 |
//
|
|
353 |
// skip the '(' and error check:
|
|
354 |
//
|
|
355 |
if(++m_position == m_end)
|
|
356 |
{
|
|
357 |
fail(regex_constants::error_paren, m_position - m_base);
|
|
358 |
return false;
|
|
359 |
}
|
|
360 |
//
|
|
361 |
// begin by checking for a perl-style (?...) extension:
|
|
362 |
//
|
|
363 |
if(
|
|
364 |
((this->flags() & (regbase::main_option_type | regbase::no_perl_ex)) == 0)
|
|
365 |
|| ((this->flags() & (regbase::main_option_type | regbase::emacs_ex)) == (regbase::basic_syntax_group|regbase::emacs_ex))
|
|
366 |
)
|
|
367 |
{
|
|
368 |
if(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_question)
|
|
369 |
return parse_perl_extension();
|
|
370 |
}
|
|
371 |
//
|
|
372 |
// update our mark count, and append the required state:
|
|
373 |
//
|
|
374 |
unsigned markid = 0;
|
|
375 |
if(0 == (this->flags() & regbase::nosubs))
|
|
376 |
{
|
|
377 |
markid = ++m_mark_count;
|
|
378 |
if(this->flags() & regbase::save_subexpression_location)
|
|
379 |
this->m_pdata->m_subs.push_back(std::pair<std::size_t, std::size_t>(std::distance(m_base, m_position) - 1, 0));
|
|
380 |
}
|
|
381 |
re_brace* pb = static_cast<re_brace*>(this->append_state(syntax_element_startmark, sizeof(re_brace)));
|
|
382 |
pb->index = markid;
|
|
383 |
std::ptrdiff_t last_paren_start = this->getoffset(pb);
|
|
384 |
// back up insertion point for alternations, and set new point:
|
|
385 |
std::ptrdiff_t last_alt_point = m_alt_insert_point;
|
|
386 |
this->m_pdata->m_data.align();
|
|
387 |
m_alt_insert_point = this->m_pdata->m_data.size();
|
|
388 |
//
|
|
389 |
// back up the current flags in case we have a nested (?imsx) group:
|
|
390 |
//
|
|
391 |
regex_constants::syntax_option_type opts = this->flags();
|
|
392 |
bool old_case_change = m_has_case_change;
|
|
393 |
m_has_case_change = false; // no changes to this scope as yet...
|
|
394 |
//
|
|
395 |
// now recursively add more states, this will terminate when we get to a
|
|
396 |
// matching ')' :
|
|
397 |
//
|
|
398 |
parse_all();
|
|
399 |
//
|
|
400 |
// Unwind pushed alternatives:
|
|
401 |
//
|
|
402 |
if(0 == unwind_alts(last_paren_start))
|
|
403 |
return false;
|
|
404 |
//
|
|
405 |
// restore flags:
|
|
406 |
//
|
|
407 |
if(m_has_case_change)
|
|
408 |
{
|
|
409 |
// the case has changed in one or more of the alternatives
|
|
410 |
// within the scoped (...) block: we have to add a state
|
|
411 |
// to reset the case sensitivity:
|
|
412 |
static_cast<re_case*>(
|
|
413 |
this->append_state(syntax_element_toggle_case, sizeof(re_case))
|
|
414 |
)->icase = opts & regbase::icase;
|
|
415 |
}
|
|
416 |
this->flags(opts);
|
|
417 |
m_has_case_change = old_case_change;
|
|
418 |
//
|
|
419 |
// we either have a ')' or we have run out of characters prematurely:
|
|
420 |
//
|
|
421 |
if(m_position == m_end)
|
|
422 |
{
|
|
423 |
this->fail(regex_constants::error_paren, ::boost::re_detail::distance(m_base, m_end));
|
|
424 |
return false;
|
|
425 |
}
|
|
426 |
BOOST_ASSERT(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_close_mark);
|
|
427 |
if(markid && (this->flags() & regbase::save_subexpression_location))
|
|
428 |
this->m_pdata->m_subs.at(markid - 1).second = std::distance(m_base, m_position);
|
|
429 |
++m_position;
|
|
430 |
//
|
|
431 |
// append closing parenthesis state:
|
|
432 |
//
|
|
433 |
pb = static_cast<re_brace*>(this->append_state(syntax_element_endmark, sizeof(re_brace)));
|
|
434 |
pb->index = markid;
|
|
435 |
this->m_paren_start = last_paren_start;
|
|
436 |
//
|
|
437 |
// restore the alternate insertion point:
|
|
438 |
//
|
|
439 |
this->m_alt_insert_point = last_alt_point;
|
|
440 |
//
|
|
441 |
// allow backrefs to this mark:
|
|
442 |
//
|
|
443 |
if((markid > 0) && (markid < sizeof(unsigned) * CHAR_BIT))
|
|
444 |
this->m_backrefs |= 1u << (markid - 1);
|
|
445 |
|
|
446 |
return true;
|
|
447 |
}
|
|
448 |
|
|
449 |
template <class charT, class traits>
|
|
450 |
bool basic_regex_parser<charT, traits>::parse_basic_escape()
|
|
451 |
{
|
|
452 |
++m_position;
|
|
453 |
bool result = true;
|
|
454 |
switch(this->m_traits.escape_syntax_type(*m_position))
|
|
455 |
{
|
|
456 |
case regex_constants::syntax_open_mark:
|
|
457 |
return parse_open_paren();
|
|
458 |
case regex_constants::syntax_close_mark:
|
|
459 |
return false;
|
|
460 |
case regex_constants::syntax_plus:
|
|
461 |
if(this->flags() & regex_constants::bk_plus_qm)
|
|
462 |
{
|
|
463 |
++m_position;
|
|
464 |
return parse_repeat(1);
|
|
465 |
}
|
|
466 |
else
|
|
467 |
return parse_literal();
|
|
468 |
case regex_constants::syntax_question:
|
|
469 |
if(this->flags() & regex_constants::bk_plus_qm)
|
|
470 |
{
|
|
471 |
++m_position;
|
|
472 |
return parse_repeat(0, 1);
|
|
473 |
}
|
|
474 |
else
|
|
475 |
return parse_literal();
|
|
476 |
case regex_constants::syntax_open_brace:
|
|
477 |
if(this->flags() & regbase::no_intervals)
|
|
478 |
return parse_literal();
|
|
479 |
++m_position;
|
|
480 |
return parse_repeat_range(true);
|
|
481 |
case regex_constants::syntax_close_brace:
|
|
482 |
if(this->flags() & regbase::no_intervals)
|
|
483 |
return parse_literal();
|
|
484 |
fail(regex_constants::error_brace, this->m_position - this->m_base);
|
|
485 |
return false;
|
|
486 |
case regex_constants::syntax_or:
|
|
487 |
if(this->flags() & regbase::bk_vbar)
|
|
488 |
return parse_alt();
|
|
489 |
else
|
|
490 |
result = parse_literal();
|
|
491 |
break;
|
|
492 |
case regex_constants::syntax_digit:
|
|
493 |
return parse_backref();
|
|
494 |
case regex_constants::escape_type_start_buffer:
|
|
495 |
if(this->flags() & regbase::emacs_ex)
|
|
496 |
{
|
|
497 |
++m_position;
|
|
498 |
this->append_state(syntax_element_buffer_start);
|
|
499 |
}
|
|
500 |
else
|
|
501 |
result = parse_literal();
|
|
502 |
break;
|
|
503 |
case regex_constants::escape_type_end_buffer:
|
|
504 |
if(this->flags() & regbase::emacs_ex)
|
|
505 |
{
|
|
506 |
++m_position;
|
|
507 |
this->append_state(syntax_element_buffer_end);
|
|
508 |
}
|
|
509 |
else
|
|
510 |
result = parse_literal();
|
|
511 |
break;
|
|
512 |
case regex_constants::escape_type_word_assert:
|
|
513 |
if(this->flags() & regbase::emacs_ex)
|
|
514 |
{
|
|
515 |
++m_position;
|
|
516 |
this->append_state(syntax_element_word_boundary);
|
|
517 |
}
|
|
518 |
else
|
|
519 |
result = parse_literal();
|
|
520 |
break;
|
|
521 |
case regex_constants::escape_type_not_word_assert:
|
|
522 |
if(this->flags() & regbase::emacs_ex)
|
|
523 |
{
|
|
524 |
++m_position;
|
|
525 |
this->append_state(syntax_element_within_word);
|
|
526 |
}
|
|
527 |
else
|
|
528 |
result = parse_literal();
|
|
529 |
break;
|
|
530 |
case regex_constants::escape_type_left_word:
|
|
531 |
if(this->flags() & regbase::emacs_ex)
|
|
532 |
{
|
|
533 |
++m_position;
|
|
534 |
this->append_state(syntax_element_word_start);
|
|
535 |
}
|
|
536 |
else
|
|
537 |
result = parse_literal();
|
|
538 |
break;
|
|
539 |
case regex_constants::escape_type_right_word:
|
|
540 |
if(this->flags() & regbase::emacs_ex)
|
|
541 |
{
|
|
542 |
++m_position;
|
|
543 |
this->append_state(syntax_element_word_end);
|
|
544 |
}
|
|
545 |
else
|
|
546 |
result = parse_literal();
|
|
547 |
break;
|
|
548 |
default:
|
|
549 |
if(this->flags() & regbase::emacs_ex)
|
|
550 |
{
|
|
551 |
bool negate = true;
|
|
552 |
switch(*m_position)
|
|
553 |
{
|
|
554 |
case 'w':
|
|
555 |
negate = false;
|
|
556 |
// fall through:
|
|
557 |
case 'W':
|
|
558 |
{
|
|
559 |
basic_char_set<charT, traits> char_set;
|
|
560 |
if(negate)
|
|
561 |
char_set.negate();
|
|
562 |
char_set.add_class(this->m_word_mask);
|
|
563 |
if(0 == this->append_set(char_set))
|
|
564 |
{
|
|
565 |
fail(regex_constants::error_ctype, m_position - m_base);
|
|
566 |
return false;
|
|
567 |
}
|
|
568 |
++m_position;
|
|
569 |
return true;
|
|
570 |
}
|
|
571 |
case 's':
|
|
572 |
negate = false;
|
|
573 |
// fall through:
|
|
574 |
case 'S':
|
|
575 |
return add_emacs_code(negate);
|
|
576 |
case 'c':
|
|
577 |
case 'C':
|
|
578 |
// not supported yet:
|
|
579 |
fail(regex_constants::error_escape, m_position - m_base);
|
|
580 |
return false;
|
|
581 |
default:
|
|
582 |
break;
|
|
583 |
}
|
|
584 |
}
|
|
585 |
result = parse_literal();
|
|
586 |
break;
|
|
587 |
}
|
|
588 |
return result;
|
|
589 |
}
|
|
590 |
|
|
591 |
template <class charT, class traits>
|
|
592 |
bool basic_regex_parser<charT, traits>::parse_extended_escape()
|
|
593 |
{
|
|
594 |
++m_position;
|
|
595 |
bool negate = false; // in case this is a character class escape: \w \d etc
|
|
596 |
switch(this->m_traits.escape_syntax_type(*m_position))
|
|
597 |
{
|
|
598 |
case regex_constants::escape_type_not_class:
|
|
599 |
negate = true;
|
|
600 |
// fall through:
|
|
601 |
case regex_constants::escape_type_class:
|
|
602 |
{
|
|
603 |
typedef typename traits::char_class_type mask_type;
|
|
604 |
mask_type m = this->m_traits.lookup_classname(m_position, m_position+1);
|
|
605 |
if(m != 0)
|
|
606 |
{
|
|
607 |
basic_char_set<charT, traits> char_set;
|
|
608 |
if(negate)
|
|
609 |
char_set.negate();
|
|
610 |
char_set.add_class(m);
|
|
611 |
if(0 == this->append_set(char_set))
|
|
612 |
{
|
|
613 |
fail(regex_constants::error_ctype, m_position - m_base);
|
|
614 |
return false;
|
|
615 |
}
|
|
616 |
++m_position;
|
|
617 |
return true;
|
|
618 |
}
|
|
619 |
//
|
|
620 |
// not a class, just a regular unknown escape:
|
|
621 |
//
|
|
622 |
this->append_literal(unescape_character());
|
|
623 |
break;
|
|
624 |
}
|
|
625 |
case regex_constants::syntax_digit:
|
|
626 |
return parse_backref();
|
|
627 |
case regex_constants::escape_type_left_word:
|
|
628 |
++m_position;
|
|
629 |
this->append_state(syntax_element_word_start);
|
|
630 |
break;
|
|
631 |
case regex_constants::escape_type_right_word:
|
|
632 |
++m_position;
|
|
633 |
this->append_state(syntax_element_word_end);
|
|
634 |
break;
|
|
635 |
case regex_constants::escape_type_start_buffer:
|
|
636 |
++m_position;
|
|
637 |
this->append_state(syntax_element_buffer_start);
|
|
638 |
break;
|
|
639 |
case regex_constants::escape_type_end_buffer:
|
|
640 |
++m_position;
|
|
641 |
this->append_state(syntax_element_buffer_end);
|
|
642 |
break;
|
|
643 |
case regex_constants::escape_type_word_assert:
|
|
644 |
++m_position;
|
|
645 |
this->append_state(syntax_element_word_boundary);
|
|
646 |
break;
|
|
647 |
case regex_constants::escape_type_not_word_assert:
|
|
648 |
++m_position;
|
|
649 |
this->append_state(syntax_element_within_word);
|
|
650 |
break;
|
|
651 |
case regex_constants::escape_type_Z:
|
|
652 |
++m_position;
|
|
653 |
this->append_state(syntax_element_soft_buffer_end);
|
|
654 |
break;
|
|
655 |
case regex_constants::escape_type_Q:
|
|
656 |
return parse_QE();
|
|
657 |
case regex_constants::escape_type_C:
|
|
658 |
return parse_match_any();
|
|
659 |
case regex_constants::escape_type_X:
|
|
660 |
++m_position;
|
|
661 |
this->append_state(syntax_element_combining);
|
|
662 |
break;
|
|
663 |
case regex_constants::escape_type_G:
|
|
664 |
++m_position;
|
|
665 |
this->append_state(syntax_element_restart_continue);
|
|
666 |
break;
|
|
667 |
case regex_constants::escape_type_not_property:
|
|
668 |
negate = true;
|
|
669 |
// fall through:
|
|
670 |
case regex_constants::escape_type_property:
|
|
671 |
{
|
|
672 |
++m_position;
|
|
673 |
char_class_type m;
|
|
674 |
if(m_position == m_end)
|
|
675 |
{
|
|
676 |
fail(regex_constants::error_escape, m_position - m_base);
|
|
677 |
return false;
|
|
678 |
}
|
|
679 |
// maybe have \p{ddd}
|
|
680 |
if(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_open_brace)
|
|
681 |
{
|
|
682 |
const charT* base = m_position;
|
|
683 |
// skip forward until we find enclosing brace:
|
|
684 |
while((m_position != m_end) && (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_brace))
|
|
685 |
++m_position;
|
|
686 |
if(m_position == m_end)
|
|
687 |
{
|
|
688 |
fail(regex_constants::error_escape, m_position - m_base);
|
|
689 |
return false;
|
|
690 |
}
|
|
691 |
m = this->m_traits.lookup_classname(++base, m_position++);
|
|
692 |
}
|
|
693 |
else
|
|
694 |
{
|
|
695 |
m = this->m_traits.lookup_classname(m_position, m_position+1);
|
|
696 |
++m_position;
|
|
697 |
}
|
|
698 |
if(m != 0)
|
|
699 |
{
|
|
700 |
basic_char_set<charT, traits> char_set;
|
|
701 |
if(negate)
|
|
702 |
char_set.negate();
|
|
703 |
char_set.add_class(m);
|
|
704 |
if(0 == this->append_set(char_set))
|
|
705 |
{
|
|
706 |
fail(regex_constants::error_ctype, m_position - m_base);
|
|
707 |
return false;
|
|
708 |
}
|
|
709 |
return true;
|
|
710 |
}
|
|
711 |
fail(regex_constants::error_ctype, m_position - m_base);
|
|
712 |
}
|
|
713 |
default:
|
|
714 |
this->append_literal(unescape_character());
|
|
715 |
break;
|
|
716 |
}
|
|
717 |
return true;
|
|
718 |
}
|
|
719 |
|
|
720 |
template <class charT, class traits>
|
|
721 |
bool basic_regex_parser<charT, traits>::parse_match_any()
|
|
722 |
{
|
|
723 |
//
|
|
724 |
// we have a '.' that can match any character:
|
|
725 |
//
|
|
726 |
++m_position;
|
|
727 |
static_cast<re_dot*>(
|
|
728 |
this->append_state(syntax_element_wild, sizeof(re_dot))
|
|
729 |
)->mask = static_cast<unsigned char>(this->flags() & regbase::no_mod_s
|
|
730 |
? re_detail::force_not_newline
|
|
731 |
: this->flags() & regbase::mod_s ?
|
|
732 |
re_detail::force_newline : re_detail::dont_care);
|
|
733 |
return true;
|
|
734 |
}
|
|
735 |
|
|
736 |
template <class charT, class traits>
|
|
737 |
bool basic_regex_parser<charT, traits>::parse_repeat(std::size_t low, std::size_t high)
|
|
738 |
{
|
|
739 |
bool greedy = true;
|
|
740 |
std::size_t insert_point;
|
|
741 |
//
|
|
742 |
// when we get to here we may have a non-greedy ? mark still to come:
|
|
743 |
//
|
|
744 |
if((m_position != m_end)
|
|
745 |
&& (
|
|
746 |
(0 == (this->flags() & (regbase::main_option_type | regbase::no_perl_ex)))
|
|
747 |
|| ((regbase::basic_syntax_group|regbase::emacs_ex) == (this->flags() & (regbase::main_option_type | regbase::emacs_ex)))
|
|
748 |
)
|
|
749 |
)
|
|
750 |
{
|
|
751 |
// OK we have a perl regex, check for a '?':
|
|
752 |
if(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_question)
|
|
753 |
{
|
|
754 |
greedy = false;
|
|
755 |
++m_position;
|
|
756 |
}
|
|
757 |
}
|
|
758 |
if(0 == this->m_last_state)
|
|
759 |
{
|
|
760 |
fail(regex_constants::error_badrepeat, ::boost::re_detail::distance(m_base, m_position));
|
|
761 |
return false;
|
|
762 |
}
|
|
763 |
if(this->m_last_state->type == syntax_element_endmark)
|
|
764 |
{
|
|
765 |
// insert a repeat before the '(' matching the last ')':
|
|
766 |
insert_point = this->m_paren_start;
|
|
767 |
}
|
|
768 |
else if((this->m_last_state->type == syntax_element_literal) && (static_cast<re_literal*>(this->m_last_state)->length > 1))
|
|
769 |
{
|
|
770 |
// the last state was a literal with more than one character, split it in two:
|
|
771 |
re_literal* lit = static_cast<re_literal*>(this->m_last_state);
|
|
772 |
charT c = (static_cast<charT*>(static_cast<void*>(lit+1)))[lit->length - 1];
|
|
773 |
--(lit->length);
|
|
774 |
// now append new state:
|
|
775 |
lit = static_cast<re_literal*>(this->append_state(syntax_element_literal, sizeof(re_literal) + sizeof(charT)));
|
|
776 |
lit->length = 1;
|
|
777 |
(static_cast<charT*>(static_cast<void*>(lit+1)))[0] = c;
|
|
778 |
insert_point = this->getoffset(this->m_last_state);
|
|
779 |
}
|
|
780 |
else
|
|
781 |
{
|
|
782 |
// repeat the last state whatever it was, need to add some error checking here:
|
|
783 |
switch(this->m_last_state->type)
|
|
784 |
{
|
|
785 |
case syntax_element_start_line:
|
|
786 |
case syntax_element_end_line:
|
|
787 |
case syntax_element_word_boundary:
|
|
788 |
case syntax_element_within_word:
|
|
789 |
case syntax_element_word_start:
|
|
790 |
case syntax_element_word_end:
|
|
791 |
case syntax_element_buffer_start:
|
|
792 |
case syntax_element_buffer_end:
|
|
793 |
case syntax_element_alt:
|
|
794 |
case syntax_element_soft_buffer_end:
|
|
795 |
case syntax_element_restart_continue:
|
|
796 |
case syntax_element_jump:
|
|
797 |
case syntax_element_startmark:
|
|
798 |
case syntax_element_backstep:
|
|
799 |
// can't legally repeat any of the above:
|
|
800 |
fail(regex_constants::error_badrepeat, m_position - m_base);
|
|
801 |
return false;
|
|
802 |
default:
|
|
803 |
// do nothing...
|
|
804 |
break;
|
|
805 |
}
|
|
806 |
insert_point = this->getoffset(this->m_last_state);
|
|
807 |
}
|
|
808 |
//
|
|
809 |
// OK we now know what to repeat, so insert the repeat around it:
|
|
810 |
//
|
|
811 |
re_repeat* rep = static_cast<re_repeat*>(this->insert_state(insert_point, syntax_element_rep, re_repeater_size));
|
|
812 |
rep->min = low;
|
|
813 |
rep->max = high;
|
|
814 |
rep->greedy = greedy;
|
|
815 |
rep->leading = false;
|
|
816 |
// store our repeater position for later:
|
|
817 |
std::ptrdiff_t rep_off = this->getoffset(rep);
|
|
818 |
// and append a back jump to the repeat:
|
|
819 |
re_jump* jmp = static_cast<re_jump*>(this->append_state(syntax_element_jump, sizeof(re_jump)));
|
|
820 |
jmp->alt.i = rep_off - this->getoffset(jmp);
|
|
821 |
this->m_pdata->m_data.align();
|
|
822 |
// now fill in the alt jump for the repeat:
|
|
823 |
rep = static_cast<re_repeat*>(this->getaddress(rep_off));
|
|
824 |
rep->alt.i = this->m_pdata->m_data.size() - rep_off;
|
|
825 |
return true;
|
|
826 |
}
|
|
827 |
|
|
828 |
template <class charT, class traits>
|
|
829 |
bool basic_regex_parser<charT, traits>::parse_repeat_range(bool isbasic)
|
|
830 |
{
|
|
831 |
//
|
|
832 |
// parse a repeat-range:
|
|
833 |
//
|
|
834 |
std::size_t min, max;
|
|
835 |
int v;
|
|
836 |
// skip whitespace:
|
|
837 |
while((m_position != m_end) && this->m_traits.isctype(*m_position, this->m_mask_space))
|
|
838 |
++m_position;
|
|
839 |
// fail if at end:
|
|
840 |
if(this->m_position == this->m_end)
|
|
841 |
{
|
|
842 |
fail(regex_constants::error_brace, this->m_position - this->m_base);
|
|
843 |
return false;
|
|
844 |
}
|
|
845 |
// get min:
|
|
846 |
v = this->m_traits.toi(m_position, m_end, 10);
|
|
847 |
// skip whitespace:
|
|
848 |
while((m_position != m_end) && this->m_traits.isctype(*m_position, this->m_mask_space))
|
|
849 |
++m_position;
|
|
850 |
if(v < 0)
|
|
851 |
{
|
|
852 |
fail(regex_constants::error_badbrace, this->m_position - this->m_base);
|
|
853 |
return false;
|
|
854 |
}
|
|
855 |
else if(this->m_position == this->m_end)
|
|
856 |
{
|
|
857 |
fail(regex_constants::error_brace, this->m_position - this->m_base);
|
|
858 |
return false;
|
|
859 |
}
|
|
860 |
min = v;
|
|
861 |
// see if we have a comma:
|
|
862 |
if(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_comma)
|
|
863 |
{
|
|
864 |
// move on and error check:
|
|
865 |
++m_position;
|
|
866 |
// skip whitespace:
|
|
867 |
while((m_position != m_end) && this->m_traits.isctype(*m_position, this->m_mask_space))
|
|
868 |
++m_position;
|
|
869 |
if(this->m_position == this->m_end)
|
|
870 |
{
|
|
871 |
fail(regex_constants::error_brace, this->m_position - this->m_base);
|
|
872 |
return false;
|
|
873 |
}
|
|
874 |
// get the value if any:
|
|
875 |
v = this->m_traits.toi(m_position, m_end, 10);
|
|
876 |
max = (v >= 0) ? v : (std::numeric_limits<std::size_t>::max)();
|
|
877 |
}
|
|
878 |
else
|
|
879 |
{
|
|
880 |
// no comma, max = min:
|
|
881 |
max = min;
|
|
882 |
}
|
|
883 |
// skip whitespace:
|
|
884 |
while((m_position != m_end) && this->m_traits.isctype(*m_position, this->m_mask_space))
|
|
885 |
++m_position;
|
|
886 |
// OK now check trailing }:
|
|
887 |
if(this->m_position == this->m_end)
|
|
888 |
{
|
|
889 |
fail(regex_constants::error_brace, this->m_position - this->m_base);
|
|
890 |
return false;
|
|
891 |
}
|
|
892 |
if(isbasic)
|
|
893 |
{
|
|
894 |
if(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_escape)
|
|
895 |
{
|
|
896 |
++m_position;
|
|
897 |
if(this->m_position == this->m_end)
|
|
898 |
{
|
|
899 |
fail(regex_constants::error_brace, this->m_position - this->m_base);
|
|
900 |
return false;
|
|
901 |
}
|
|
902 |
}
|
|
903 |
else
|
|
904 |
{
|
|
905 |
fail(regex_constants::error_badbrace, this->m_position - this->m_base);
|
|
906 |
return false;
|
|
907 |
}
|
|
908 |
}
|
|
909 |
if(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_close_brace)
|
|
910 |
++m_position;
|
|
911 |
else
|
|
912 |
{
|
|
913 |
fail(regex_constants::error_badbrace, this->m_position - this->m_base);
|
|
914 |
return false;
|
|
915 |
}
|
|
916 |
//
|
|
917 |
// finally go and add the repeat, unless error:
|
|
918 |
//
|
|
919 |
if(min > max)
|
|
920 |
{
|
|
921 |
fail(regex_constants::error_badbrace, this->m_position - this->m_base);
|
|
922 |
return false;
|
|
923 |
}
|
|
924 |
return parse_repeat(min, max);
|
|
925 |
}
|
|
926 |
|
|
927 |
template <class charT, class traits>
|
|
928 |
bool basic_regex_parser<charT, traits>::parse_alt()
|
|
929 |
{
|
|
930 |
//
|
|
931 |
// error check: if there have been no previous states,
|
|
932 |
// or if the last state was a '(' then error:
|
|
933 |
//
|
|
934 |
if(
|
|
935 |
((this->m_last_state == 0) || (this->m_last_state->type == syntax_element_startmark))
|
|
936 |
&&
|
|
937 |
!(
|
|
938 |
((this->flags() & regbase::main_option_type) == regbase::perl_syntax_group)
|
|
939 |
&&
|
|
940 |
((this->flags() & regbase::no_empty_expressions) == 0)
|
|
941 |
)
|
|
942 |
)
|
|
943 |
{
|
|
944 |
fail(regex_constants::error_empty, this->m_position - this->m_base);
|
|
945 |
return false;
|
|
946 |
}
|
|
947 |
++m_position;
|
|
948 |
//
|
|
949 |
// we need to append a trailing jump:
|
|
950 |
//
|
|
951 |
re_syntax_base* pj = this->append_state(re_detail::syntax_element_jump, sizeof(re_jump));
|
|
952 |
std::ptrdiff_t jump_offset = this->getoffset(pj);
|
|
953 |
//
|
|
954 |
// now insert the alternative:
|
|
955 |
//
|
|
956 |
re_alt* palt = static_cast<re_alt*>(this->insert_state(this->m_alt_insert_point, syntax_element_alt, re_alt_size));
|
|
957 |
jump_offset += re_alt_size;
|
|
958 |
this->m_pdata->m_data.align();
|
|
959 |
palt->alt.i = this->m_pdata->m_data.size() - this->getoffset(palt);
|
|
960 |
//
|
|
961 |
// update m_alt_insert_point so that the next alternate gets
|
|
962 |
// inserted at the start of the second of the two we've just created:
|
|
963 |
//
|
|
964 |
this->m_alt_insert_point = this->m_pdata->m_data.size();
|
|
965 |
//
|
|
966 |
// the start of this alternative must have a case changes state
|
|
967 |
// if the current block has messed around with case changes:
|
|
968 |
//
|
|
969 |
if(m_has_case_change)
|
|
970 |
{
|
|
971 |
static_cast<re_case*>(
|
|
972 |
this->append_state(syntax_element_toggle_case, sizeof(re_case))
|
|
973 |
)->icase = this->m_icase;
|
|
974 |
}
|
|
975 |
//
|
|
976 |
// push the alternative onto our stack, a recursive
|
|
977 |
// implementation here is easier to understand (and faster
|
|
978 |
// as it happens), but causes all kinds of stack overflow problems
|
|
979 |
// on programs with small stacks (COM+).
|
|
980 |
//
|
|
981 |
m_alt_jumps.push_back(jump_offset);
|
|
982 |
return true;
|
|
983 |
}
|
|
984 |
|
|
985 |
template <class charT, class traits>
|
|
986 |
bool basic_regex_parser<charT, traits>::parse_set()
|
|
987 |
{
|
|
988 |
++m_position;
|
|
989 |
if(m_position == m_end)
|
|
990 |
{
|
|
991 |
fail(regex_constants::error_brack, m_position - m_base);
|
|
992 |
return false;
|
|
993 |
}
|
|
994 |
basic_char_set<charT, traits> char_set;
|
|
995 |
|
|
996 |
const charT* base = m_position; // where the '[' was
|
|
997 |
const charT* item_base = m_position; // where the '[' or '^' was
|
|
998 |
|
|
999 |
while(m_position != m_end)
|
|
1000 |
{
|
|
1001 |
switch(this->m_traits.syntax_type(*m_position))
|
|
1002 |
{
|
|
1003 |
case regex_constants::syntax_caret:
|
|
1004 |
if(m_position == base)
|
|
1005 |
{
|
|
1006 |
char_set.negate();
|
|
1007 |
++m_position;
|
|
1008 |
item_base = m_position;
|
|
1009 |
}
|
|
1010 |
else
|
|
1011 |
parse_set_literal(char_set);
|
|
1012 |
break;
|
|
1013 |
case regex_constants::syntax_close_set:
|
|
1014 |
if(m_position == item_base)
|
|
1015 |
{
|
|
1016 |
parse_set_literal(char_set);
|
|
1017 |
break;
|
|
1018 |
}
|
|
1019 |
else
|
|
1020 |
{
|
|
1021 |
++m_position;
|
|
1022 |
if(0 == this->append_set(char_set))
|
|
1023 |
{
|
|
1024 |
fail(regex_constants::error_range, m_position - m_base);
|
|
1025 |
return false;
|
|
1026 |
}
|
|
1027 |
}
|
|
1028 |
return true;
|
|
1029 |
case regex_constants::syntax_open_set:
|
|
1030 |
if(parse_inner_set(char_set))
|
|
1031 |
break;
|
|
1032 |
return true;
|
|
1033 |
case regex_constants::syntax_escape:
|
|
1034 |
{
|
|
1035 |
//
|
|
1036 |
// look ahead and see if this is a character class shortcut
|
|
1037 |
// \d \w \s etc...
|
|
1038 |
//
|
|
1039 |
++m_position;
|
|
1040 |
if(this->m_traits.escape_syntax_type(*m_position)
|
|
1041 |
== regex_constants::escape_type_class)
|
|
1042 |
{
|
|
1043 |
char_class_type m = this->m_traits.lookup_classname(m_position, m_position+1);
|
|
1044 |
if(m != 0)
|
|
1045 |
{
|
|
1046 |
char_set.add_class(m);
|
|
1047 |
++m_position;
|
|
1048 |
break;
|
|
1049 |
}
|
|
1050 |
}
|
|
1051 |
else if(this->m_traits.escape_syntax_type(*m_position)
|
|
1052 |
== regex_constants::escape_type_not_class)
|
|
1053 |
{
|
|
1054 |
// negated character class:
|
|
1055 |
char_class_type m = this->m_traits.lookup_classname(m_position, m_position+1);
|
|
1056 |
if(m != 0)
|
|
1057 |
{
|
|
1058 |
char_set.add_negated_class(m);
|
|
1059 |
++m_position;
|
|
1060 |
break;
|
|
1061 |
}
|
|
1062 |
}
|
|
1063 |
// not a character class, just a regular escape:
|
|
1064 |
--m_position;
|
|
1065 |
parse_set_literal(char_set);
|
|
1066 |
break;
|
|
1067 |
}
|
|
1068 |
default:
|
|
1069 |
parse_set_literal(char_set);
|
|
1070 |
break;
|
|
1071 |
}
|
|
1072 |
}
|
|
1073 |
return m_position != m_end;
|
|
1074 |
}
|
|
1075 |
|
|
1076 |
template <class charT, class traits>
|
|
1077 |
bool basic_regex_parser<charT, traits>::parse_inner_set(basic_char_set<charT, traits>& char_set)
|
|
1078 |
{
|
|
1079 |
//
|
|
1080 |
// we have either a character class [:name:]
|
|
1081 |
// a collating element [.name.]
|
|
1082 |
// or an equivalence class [=name=]
|
|
1083 |
//
|
|
1084 |
if(m_end == ++m_position)
|
|
1085 |
{
|
|
1086 |
fail(regex_constants::error_brack, m_position - m_base);
|
|
1087 |
return false;
|
|
1088 |
}
|
|
1089 |
switch(this->m_traits.syntax_type(*m_position))
|
|
1090 |
{
|
|
1091 |
case regex_constants::syntax_dot:
|
|
1092 |
//
|
|
1093 |
// a collating element is treated as a literal:
|
|
1094 |
//
|
|
1095 |
--m_position;
|
|
1096 |
parse_set_literal(char_set);
|
|
1097 |
return true;
|
|
1098 |
case regex_constants::syntax_colon:
|
|
1099 |
{
|
|
1100 |
// check that character classes are actually enabled:
|
|
1101 |
if((this->flags() & (regbase::main_option_type | regbase::no_char_classes))
|
|
1102 |
== (regbase::basic_syntax_group | regbase::no_char_classes))
|
|
1103 |
{
|
|
1104 |
--m_position;
|
|
1105 |
parse_set_literal(char_set);
|
|
1106 |
return true;
|
|
1107 |
}
|
|
1108 |
// skip the ':'
|
|
1109 |
if(m_end == ++m_position)
|
|
1110 |
{
|
|
1111 |
fail(regex_constants::error_brack, m_position - m_base);
|
|
1112 |
return false;
|
|
1113 |
}
|
|
1114 |
const charT* name_first = m_position;
|
|
1115 |
// skip at least one character, then find the matching ':]'
|
|
1116 |
if(m_end == ++m_position)
|
|
1117 |
{
|
|
1118 |
fail(regex_constants::error_brack, m_position - m_base);
|
|
1119 |
return false;
|
|
1120 |
}
|
|
1121 |
while((m_position != m_end)
|
|
1122 |
&& (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_colon))
|
|
1123 |
++m_position;
|
|
1124 |
const charT* name_last = m_position;
|
|
1125 |
if(m_end == m_position)
|
|
1126 |
{
|
|
1127 |
fail(regex_constants::error_brack, m_position - m_base);
|
|
1128 |
return false;
|
|
1129 |
}
|
|
1130 |
if((m_end == ++m_position)
|
|
1131 |
|| (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_set))
|
|
1132 |
{
|
|
1133 |
fail(regex_constants::error_brack, m_position - m_base);
|
|
1134 |
return false;
|
|
1135 |
}
|
|
1136 |
//
|
|
1137 |
// check for negated class:
|
|
1138 |
//
|
|
1139 |
bool negated = false;
|
|
1140 |
if(this->m_traits.syntax_type(*name_first) == regex_constants::syntax_caret)
|
|
1141 |
{
|
|
1142 |
++name_first;
|
|
1143 |
negated = true;
|
|
1144 |
}
|
|
1145 |
typedef typename traits::char_class_type mask_type;
|
|
1146 |
mask_type m = this->m_traits.lookup_classname(name_first, name_last);
|
|
1147 |
if(m == 0)
|
|
1148 |
{
|
|
1149 |
if(char_set.empty() && (name_last - name_first == 1))
|
|
1150 |
{
|
|
1151 |
// maybe a special case:
|
|
1152 |
++m_position;
|
|
1153 |
if( (m_position != m_end)
|
|
1154 |
&& (this->m_traits.syntax_type(*m_position)
|
|
1155 |
== regex_constants::syntax_close_set))
|
|
1156 |
{
|
|
1157 |
if(this->m_traits.escape_syntax_type(*name_first)
|
|
1158 |
== regex_constants::escape_type_left_word)
|
|
1159 |
{
|
|
1160 |
++m_position;
|
|
1161 |
this->append_state(syntax_element_word_start);
|
|
1162 |
return false;
|
|
1163 |
}
|
|
1164 |
if(this->m_traits.escape_syntax_type(*name_first)
|
|
1165 |
== regex_constants::escape_type_right_word)
|
|
1166 |
{
|
|
1167 |
++m_position;
|
|
1168 |
this->append_state(syntax_element_word_end);
|
|
1169 |
return false;
|
|
1170 |
}
|
|
1171 |
}
|
|
1172 |
}
|
|
1173 |
fail(regex_constants::error_ctype, name_first - m_base);
|
|
1174 |
return false;
|
|
1175 |
}
|
|
1176 |
if(negated == false)
|
|
1177 |
char_set.add_class(m);
|
|
1178 |
else
|
|
1179 |
char_set.add_negated_class(m);
|
|
1180 |
++m_position;
|
|
1181 |
break;
|
|
1182 |
}
|
|
1183 |
case regex_constants::syntax_equal:
|
|
1184 |
{
|
|
1185 |
// skip the '='
|
|
1186 |
if(m_end == ++m_position)
|
|
1187 |
{
|
|
1188 |
fail(regex_constants::error_brack, m_position - m_base);
|
|
1189 |
return false;
|
|
1190 |
}
|
|
1191 |
const charT* name_first = m_position;
|
|
1192 |
// skip at least one character, then find the matching '=]'
|
|
1193 |
if(m_end == ++m_position)
|
|
1194 |
{
|
|
1195 |
fail(regex_constants::error_brack, m_position - m_base);
|
|
1196 |
return false;
|
|
1197 |
}
|
|
1198 |
while((m_position != m_end)
|
|
1199 |
&& (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_equal))
|
|
1200 |
++m_position;
|
|
1201 |
const charT* name_last = m_position;
|
|
1202 |
if(m_end == m_position)
|
|
1203 |
{
|
|
1204 |
fail(regex_constants::error_brack, m_position - m_base);
|
|
1205 |
return false;
|
|
1206 |
}
|
|
1207 |
if((m_end == ++m_position)
|
|
1208 |
|| (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_set))
|
|
1209 |
{
|
|
1210 |
fail(regex_constants::error_brack, m_position - m_base);
|
|
1211 |
return false;
|
|
1212 |
}
|
|
1213 |
string_type m = this->m_traits.lookup_collatename(name_first, name_last);
|
|
1214 |
if((0 == m.size()) || (m.size() > 2))
|
|
1215 |
{
|
|
1216 |
fail(regex_constants::error_collate, name_first - m_base);
|
|
1217 |
return false;
|
|
1218 |
}
|
|
1219 |
digraph<charT> d;
|
|
1220 |
d.first = m[0];
|
|
1221 |
if(m.size() > 1)
|
|
1222 |
d.second = m[1];
|
|
1223 |
else
|
|
1224 |
d.second = 0;
|
|
1225 |
char_set.add_equivalent(d);
|
|
1226 |
++m_position;
|
|
1227 |
break;
|
|
1228 |
}
|
|
1229 |
default:
|
|
1230 |
--m_position;
|
|
1231 |
parse_set_literal(char_set);
|
|
1232 |
break;
|
|
1233 |
}
|
|
1234 |
return true;
|
|
1235 |
}
|
|
1236 |
|
|
1237 |
template <class charT, class traits>
|
|
1238 |
void basic_regex_parser<charT, traits>::parse_set_literal(basic_char_set<charT, traits>& char_set)
|
|
1239 |
{
|
|
1240 |
digraph<charT> start_range(get_next_set_literal(char_set));
|
|
1241 |
if(m_end == m_position)
|
|
1242 |
{
|
|
1243 |
fail(regex_constants::error_brack, m_position - m_base);
|
|
1244 |
return;
|
|
1245 |
}
|
|
1246 |
if(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_dash)
|
|
1247 |
{
|
|
1248 |
// we have a range:
|
|
1249 |
if(m_end == ++m_position)
|
|
1250 |
{
|
|
1251 |
fail(regex_constants::error_brack, m_position - m_base);
|
|
1252 |
return;
|
|
1253 |
}
|
|
1254 |
if(this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_set)
|
|
1255 |
{
|
|
1256 |
digraph<charT> end_range = get_next_set_literal(char_set);
|
|
1257 |
char_set.add_range(start_range, end_range);
|
|
1258 |
if(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_dash)
|
|
1259 |
{
|
|
1260 |
if(m_end == ++m_position)
|
|
1261 |
{
|
|
1262 |
fail(regex_constants::error_brack, m_position - m_base);
|
|
1263 |
return;
|
|
1264 |
}
|
|
1265 |
if(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_close_set)
|
|
1266 |
{
|
|
1267 |
// trailing - :
|
|
1268 |
--m_position;
|
|
1269 |
return;
|
|
1270 |
}
|
|
1271 |
fail(regex_constants::error_range, m_position - m_base);
|
|
1272 |
return;
|
|
1273 |
}
|
|
1274 |
return;
|
|
1275 |
}
|
|
1276 |
--m_position;
|
|
1277 |
}
|
|
1278 |
char_set.add_single(start_range);
|
|
1279 |
}
|
|
1280 |
|
|
1281 |
template <class charT, class traits>
|
|
1282 |
digraph<charT> basic_regex_parser<charT, traits>::get_next_set_literal(basic_char_set<charT, traits>& char_set)
|
|
1283 |
{
|
|
1284 |
digraph<charT> result;
|
|
1285 |
switch(this->m_traits.syntax_type(*m_position))
|
|
1286 |
{
|
|
1287 |
case regex_constants::syntax_dash:
|
|
1288 |
if(!char_set.empty())
|
|
1289 |
{
|
|
1290 |
// see if we are at the end of the set:
|
|
1291 |
if((++m_position == m_end) || (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_set))
|
|
1292 |
{
|
|
1293 |
fail(regex_constants::error_range, m_position - m_base);
|
|
1294 |
return result;
|
|
1295 |
}
|
|
1296 |
--m_position;
|
|
1297 |
}
|
|
1298 |
result.first = *m_position++;
|
|
1299 |
return result;
|
|
1300 |
case regex_constants::syntax_escape:
|
|
1301 |
// check to see if escapes are supported first:
|
|
1302 |
if(this->flags() & regex_constants::no_escape_in_lists)
|
|
1303 |
{
|
|
1304 |
result = *m_position++;
|
|
1305 |
break;
|
|
1306 |
}
|
|
1307 |
++m_position;
|
|
1308 |
result = unescape_character();
|
|
1309 |
break;
|
|
1310 |
case regex_constants::syntax_open_set:
|
|
1311 |
{
|
|
1312 |
if(m_end == ++m_position)
|
|
1313 |
{
|
|
1314 |
fail(regex_constants::error_collate, m_position - m_base);
|
|
1315 |
return result;
|
|
1316 |
}
|
|
1317 |
if(this->m_traits.syntax_type(*m_position) != regex_constants::syntax_dot)
|
|
1318 |
{
|
|
1319 |
--m_position;
|
|
1320 |
result.first = *m_position;
|
|
1321 |
++m_position;
|
|
1322 |
return result;
|
|
1323 |
}
|
|
1324 |
if(m_end == ++m_position)
|
|
1325 |
{
|
|
1326 |
fail(regex_constants::error_collate, m_position - m_base);
|
|
1327 |
return result;
|
|
1328 |
}
|
|
1329 |
const charT* name_first = m_position;
|
|
1330 |
// skip at least one character, then find the matching ':]'
|
|
1331 |
if(m_end == ++m_position)
|
|
1332 |
{
|
|
1333 |
fail(regex_constants::error_collate, name_first - m_base);
|
|
1334 |
return result;
|
|
1335 |
}
|
|
1336 |
while((m_position != m_end)
|
|
1337 |
&& (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_dot))
|
|
1338 |
++m_position;
|
|
1339 |
const charT* name_last = m_position;
|
|
1340 |
if(m_end == m_position)
|
|
1341 |
{
|
|
1342 |
fail(regex_constants::error_collate, name_first - m_base);
|
|
1343 |
return result;
|
|
1344 |
}
|
|
1345 |
if((m_end == ++m_position)
|
|
1346 |
|| (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_set))
|
|
1347 |
{
|
|
1348 |
fail(regex_constants::error_collate, name_first - m_base);
|
|
1349 |
return result;
|
|
1350 |
}
|
|
1351 |
++m_position;
|
|
1352 |
string_type s = this->m_traits.lookup_collatename(name_first, name_last);
|
|
1353 |
if(s.empty() || (s.size() > 2))
|
|
1354 |
{
|
|
1355 |
fail(regex_constants::error_collate, name_first - m_base);
|
|
1356 |
return result;
|
|
1357 |
}
|
|
1358 |
result.first = s[0];
|
|
1359 |
if(s.size() > 1)
|
|
1360 |
result.second = s[1];
|
|
1361 |
else
|
|
1362 |
result.second = 0;
|
|
1363 |
return result;
|
|
1364 |
}
|
|
1365 |
default:
|
|
1366 |
result = *m_position++;
|
|
1367 |
}
|
|
1368 |
return result;
|
|
1369 |
}
|
|
1370 |
|
|
1371 |
//
|
|
1372 |
// does a value fit in the specified charT type?
|
|
1373 |
//
|
|
1374 |
template <class charT>
|
|
1375 |
bool valid_value(charT, int v, const mpl::true_&)
|
|
1376 |
{
|
|
1377 |
return (v >> (sizeof(charT) * CHAR_BIT)) == 0;
|
|
1378 |
}
|
|
1379 |
template <class charT>
|
|
1380 |
bool valid_value(charT, int, const mpl::false_&)
|
|
1381 |
{
|
|
1382 |
return true; // v will alsways fit in a charT
|
|
1383 |
}
|
|
1384 |
template <class charT>
|
|
1385 |
bool valid_value(charT c, int v)
|
|
1386 |
{
|
|
1387 |
return valid_value(c, v, mpl::bool_<(sizeof(charT) < sizeof(int))>());
|
|
1388 |
}
|
|
1389 |
|
|
1390 |
template <class charT, class traits>
|
|
1391 |
charT basic_regex_parser<charT, traits>::unescape_character()
|
|
1392 |
{
|
|
1393 |
#ifdef BOOST_MSVC
|
|
1394 |
#pragma warning(push)
|
|
1395 |
#pragma warning(disable:4127)
|
|
1396 |
#endif
|
|
1397 |
charT result(0);
|
|
1398 |
if(m_position == m_end)
|
|
1399 |
{
|
|
1400 |
fail(regex_constants::error_escape, m_position - m_base);
|
|
1401 |
return false;
|
|
1402 |
}
|
|
1403 |
switch(this->m_traits.escape_syntax_type(*m_position))
|
|
1404 |
{
|
|
1405 |
case regex_constants::escape_type_control_a:
|
|
1406 |
result = charT('\a');
|
|
1407 |
break;
|
|
1408 |
case regex_constants::escape_type_e:
|
|
1409 |
result = charT(27);
|
|
1410 |
break;
|
|
1411 |
case regex_constants::escape_type_control_f:
|
|
1412 |
result = charT('\f');
|
|
1413 |
break;
|
|
1414 |
case regex_constants::escape_type_control_n:
|
|
1415 |
result = charT('\n');
|
|
1416 |
break;
|
|
1417 |
case regex_constants::escape_type_control_r:
|
|
1418 |
result = charT('\r');
|
|
1419 |
break;
|
|
1420 |
case regex_constants::escape_type_control_t:
|
|
1421 |
result = charT('\t');
|
|
1422 |
break;
|
|
1423 |
case regex_constants::escape_type_control_v:
|
|
1424 |
result = charT('\v');
|
|
1425 |
break;
|
|
1426 |
case regex_constants::escape_type_word_assert:
|
|
1427 |
result = charT('\b');
|
|
1428 |
break;
|
|
1429 |
case regex_constants::escape_type_ascii_control:
|
|
1430 |
++m_position;
|
|
1431 |
if(m_position == m_end)
|
|
1432 |
{
|
|
1433 |
fail(regex_constants::error_escape, m_position - m_base);
|
|
1434 |
return result;
|
|
1435 |
}
|
|
1436 |
/*
|
|
1437 |
if((*m_position < charT('@'))
|
|
1438 |
|| (*m_position > charT(125)) )
|
|
1439 |
{
|
|
1440 |
fail(regex_constants::error_escape, m_position - m_base);
|
|
1441 |
return result;
|
|
1442 |
}
|
|
1443 |
*/
|
|
1444 |
result = static_cast<charT>(*m_position % 32);
|
|
1445 |
break;
|
|
1446 |
case regex_constants::escape_type_hex:
|
|
1447 |
++m_position;
|
|
1448 |
if(m_position == m_end)
|
|
1449 |
{
|
|
1450 |
fail(regex_constants::error_escape, m_position - m_base);
|
|
1451 |
return result;
|
|
1452 |
}
|
|
1453 |
// maybe have \x{ddd}
|
|
1454 |
if(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_open_brace)
|
|
1455 |
{
|
|
1456 |
++m_position;
|
|
1457 |
if(m_position == m_end)
|
|
1458 |
{
|
|
1459 |
fail(regex_constants::error_escape, m_position - m_base);
|
|
1460 |
return result;
|
|
1461 |
}
|
|
1462 |
int i = this->m_traits.toi(m_position, m_end, 16);
|
|
1463 |
if((m_position == m_end)
|
|
1464 |
|| (i < 0)
|
|
1465 |
|| ((std::numeric_limits<charT>::is_specialized) && (charT(i) > (std::numeric_limits<charT>::max)()))
|
|
1466 |
|| (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_brace))
|
|
1467 |
{
|
|
1468 |
fail(regex_constants::error_badbrace, m_position - m_base);
|
|
1469 |
return result;
|
|
1470 |
}
|
|
1471 |
++m_position;
|
|
1472 |
result = charT(i);
|
|
1473 |
}
|
|
1474 |
else
|
|
1475 |
{
|
|
1476 |
std::ptrdiff_t len = (std::min)(static_cast<std::ptrdiff_t>(2), m_end - m_position);
|
|
1477 |
int i = this->m_traits.toi(m_position, m_position + len, 16);
|
|
1478 |
if((i < 0)
|
|
1479 |
|| !valid_value(charT(0), i))
|
|
1480 |
{
|
|
1481 |
fail(regex_constants::error_escape, m_position - m_base);
|
|
1482 |
return result;
|
|
1483 |
}
|
|
1484 |
result = charT(i);
|
|
1485 |
}
|
|
1486 |
return result;
|
|
1487 |
case regex_constants::syntax_digit:
|
|
1488 |
{
|
|
1489 |
// an octal escape sequence, the first character must be a zero
|
|
1490 |
// followed by up to 3 octal digits:
|
|
1491 |
std::ptrdiff_t len = (std::min)(::boost::re_detail::distance(m_position, m_end), static_cast<std::ptrdiff_t>(4));
|
|
1492 |
const charT* bp = m_position;
|
|
1493 |
int val = this->m_traits.toi(bp, bp + 1, 8);
|
|
1494 |
if(val != 0)
|
|
1495 |
{
|
|
1496 |
// Oops not an octal escape after all:
|
|
1497 |
fail(regex_constants::error_escape, m_position - m_base);
|
|
1498 |
return result;
|
|
1499 |
}
|
|
1500 |
val = this->m_traits.toi(m_position, m_position + len, 8);
|
|
1501 |
if(val < 0)
|
|
1502 |
{
|
|
1503 |
fail(regex_constants::error_escape, m_position - m_base);
|
|
1504 |
return result;
|
|
1505 |
}
|
|
1506 |
return static_cast<charT>(val);
|
|
1507 |
}
|
|
1508 |
case regex_constants::escape_type_named_char:
|
|
1509 |
{
|
|
1510 |
++m_position;
|
|
1511 |
if(m_position == m_end)
|
|
1512 |
{
|
|
1513 |
fail(regex_constants::error_escape, m_position - m_base);
|
|
1514 |
return false;
|
|
1515 |
}
|
|
1516 |
// maybe have \N{name}
|
|
1517 |
if(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_open_brace)
|
|
1518 |
{
|
|
1519 |
const charT* base = m_position;
|
|
1520 |
// skip forward until we find enclosing brace:
|
|
1521 |
while((m_position != m_end) && (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_brace))
|
|
1522 |
++m_position;
|
|
1523 |
if(m_position == m_end)
|
|
1524 |
{
|
|
1525 |
fail(regex_constants::error_escape, m_position - m_base);
|
|
1526 |
return false;
|
|
1527 |
}
|
|
1528 |
string_type s = this->m_traits.lookup_collatename(++base, m_position++);
|
|
1529 |
if(s.empty())
|
|
1530 |
{
|
|
1531 |
fail(regex_constants::error_collate, m_position - m_base);
|
|
1532 |
return false;
|
|
1533 |
}
|
|
1534 |
if(s.size() == 1)
|
|
1535 |
{
|
|
1536 |
return s[0];
|
|
1537 |
}
|
|
1538 |
}
|
|
1539 |
// fall through is a failure:
|
|
1540 |
fail(regex_constants::error_escape, m_position - m_base);
|
|
1541 |
return false;
|
|
1542 |
}
|
|
1543 |
default:
|
|
1544 |
result = *m_position;
|
|
1545 |
break;
|
|
1546 |
}
|
|
1547 |
++m_position;
|
|
1548 |
return result;
|
|
1549 |
#ifdef BOOST_MSVC
|
|
1550 |
#pragma warning(pop)
|
|
1551 |
#endif
|
|
1552 |
}
|
|
1553 |
|
|
1554 |
template <class charT, class traits>
|
|
1555 |
bool basic_regex_parser<charT, traits>::parse_backref()
|
|
1556 |
{
|
|
1557 |
BOOST_ASSERT(m_position != m_end);
|
|
1558 |
const charT* pc = m_position;
|
|
1559 |
int i = this->m_traits.toi(pc, pc + 1, 10);
|
|
1560 |
if((i == 0) || (((this->flags() & regbase::main_option_type) == regbase::perl_syntax_group) && (this->flags() & regbase::no_bk_refs)))
|
|
1561 |
{
|
|
1562 |
// not a backref at all but an octal escape sequence:
|
|
1563 |
charT c = unescape_character();
|
|
1564 |
this->append_literal(c);
|
|
1565 |
}
|
|
1566 |
else if((i > 0) && (this->m_backrefs & (1u << (i-1))))
|
|
1567 |
{
|
|
1568 |
m_position = pc;
|
|
1569 |
re_brace* pb = static_cast<re_brace*>(this->append_state(syntax_element_backref, sizeof(re_brace)));
|
|
1570 |
pb->index = i;
|
|
1571 |
}
|
|
1572 |
else
|
|
1573 |
{
|
|
1574 |
fail(regex_constants::error_backref, m_position - m_end);
|
|
1575 |
return false;
|
|
1576 |
}
|
|
1577 |
return true;
|
|
1578 |
}
|
|
1579 |
|
|
1580 |
template <class charT, class traits>
|
|
1581 |
bool basic_regex_parser<charT, traits>::parse_QE()
|
|
1582 |
{
|
|
1583 |
#ifdef BOOST_MSVC
|
|
1584 |
#pragma warning(push)
|
|
1585 |
#pragma warning(disable:4127)
|
|
1586 |
#endif
|
|
1587 |
//
|
|
1588 |
// parse a \Q...\E sequence:
|
|
1589 |
//
|
|
1590 |
++m_position; // skip the Q
|
|
1591 |
const charT* start = m_position;
|
|
1592 |
const charT* end;
|
|
1593 |
do
|
|
1594 |
{
|
|
1595 |
while((m_position != m_end)
|
|
1596 |
&& (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_escape))
|
|
1597 |
++m_position;
|
|
1598 |
if(m_position == m_end)
|
|
1599 |
{
|
|
1600 |
// a \Q...\E sequence may terminate with the end of the expression:
|
|
1601 |
end = m_position;
|
|
1602 |
break;
|
|
1603 |
}
|
|
1604 |
if(++m_position == m_end) // skip the escape
|
|
1605 |
{
|
|
1606 |
fail(regex_constants::error_escape, m_position - m_base);
|
|
1607 |
return false;
|
|
1608 |
}
|
|
1609 |
// check to see if it's a \E:
|
|
1610 |
if(this->m_traits.escape_syntax_type(*m_position) == regex_constants::escape_type_E)
|
|
1611 |
{
|
|
1612 |
++m_position;
|
|
1613 |
end = m_position - 2;
|
|
1614 |
break;
|
|
1615 |
}
|
|
1616 |
// otherwise go round again:
|
|
1617 |
}while(true);
|
|
1618 |
//
|
|
1619 |
// now add all the character between the two escapes as literals:
|
|
1620 |
//
|
|
1621 |
while(start != end)
|
|
1622 |
{
|
|
1623 |
this->append_literal(*start);
|
|
1624 |
++start;
|
|
1625 |
}
|
|
1626 |
return true;
|
|
1627 |
#ifdef BOOST_MSVC
|
|
1628 |
#pragma warning(pop)
|
|
1629 |
#endif
|
|
1630 |
}
|
|
1631 |
|
|
1632 |
template <class charT, class traits>
|
|
1633 |
bool basic_regex_parser<charT, traits>::parse_perl_extension()
|
|
1634 |
{
|
|
1635 |
if(++m_position == m_end)
|
|
1636 |
{
|
|
1637 |
fail(regex_constants::error_badrepeat, m_position - m_base);
|
|
1638 |
return false;
|
|
1639 |
}
|
|
1640 |
//
|
|
1641 |
// treat comments as a special case, as these
|
|
1642 |
// are the only ones that don't start with a leading
|
|
1643 |
// startmark state:
|
|
1644 |
//
|
|
1645 |
if(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_hash)
|
|
1646 |
{
|
|
1647 |
while((m_position != m_end)
|
|
1648 |
&& (this->m_traits.syntax_type(*m_position++) != regex_constants::syntax_close_mark))
|
|
1649 |
{}
|
|
1650 |
return true;
|
|
1651 |
}
|
|
1652 |
//
|
|
1653 |
// backup some state, and prepare the way:
|
|
1654 |
//
|
|
1655 |
int markid = 0;
|
|
1656 |
std::ptrdiff_t jump_offset = 0;
|
|
1657 |
re_brace* pb = static_cast<re_brace*>(this->append_state(syntax_element_startmark, sizeof(re_brace)));
|
|
1658 |
std::ptrdiff_t last_paren_start = this->getoffset(pb);
|
|
1659 |
// back up insertion point for alternations, and set new point:
|
|
1660 |
std::ptrdiff_t last_alt_point = m_alt_insert_point;
|
|
1661 |
this->m_pdata->m_data.align();
|
|
1662 |
m_alt_insert_point = this->m_pdata->m_data.size();
|
|
1663 |
std::ptrdiff_t expected_alt_point = m_alt_insert_point;
|
|
1664 |
bool restore_flags = true;
|
|
1665 |
regex_constants::syntax_option_type old_flags = this->flags();
|
|
1666 |
bool old_case_change = m_has_case_change;
|
|
1667 |
m_has_case_change = false;
|
|
1668 |
//
|
|
1669 |
// select the actual extension used:
|
|
1670 |
//
|
|
1671 |
switch(this->m_traits.syntax_type(*m_position))
|
|
1672 |
{
|
|
1673 |
case regex_constants::syntax_colon:
|
|
1674 |
//
|
|
1675 |
// a non-capturing mark:
|
|
1676 |
//
|
|
1677 |
pb->index = markid = 0;
|
|
1678 |
++m_position;
|
|
1679 |
break;
|
|
1680 |
case regex_constants::syntax_equal:
|
|
1681 |
pb->index = markid = -1;
|
|
1682 |
++m_position;
|
|
1683 |
jump_offset = this->getoffset(this->append_state(syntax_element_jump, sizeof(re_jump)));
|
|
1684 |
this->m_pdata->m_data.align();
|
|
1685 |
m_alt_insert_point = this->m_pdata->m_data.size();
|
|
1686 |
break;
|
|
1687 |
case regex_constants::syntax_not:
|
|
1688 |
pb->index = markid = -2;
|
|
1689 |
++m_position;
|
|
1690 |
jump_offset = this->getoffset(this->append_state(syntax_element_jump, sizeof(re_jump)));
|
|
1691 |
this->m_pdata->m_data.align();
|
|
1692 |
m_alt_insert_point = this->m_pdata->m_data.size();
|
|
1693 |
break;
|
|
1694 |
case regex_constants::escape_type_left_word:
|
|
1695 |
{
|
|
1696 |
// a lookbehind assertion:
|
|
1697 |
if(++m_position == m_end)
|
|
1698 |
{
|
|
1699 |
fail(regex_constants::error_badrepeat, m_position - m_base);
|
|
1700 |
return false;
|
|
1701 |
}
|
|
1702 |
regex_constants::syntax_type t = this->m_traits.syntax_type(*m_position);
|
|
1703 |
if(t == regex_constants::syntax_not)
|
|
1704 |
pb->index = markid = -2;
|
|
1705 |
else if(t == regex_constants::syntax_equal)
|
|
1706 |
pb->index = markid = -1;
|
|
1707 |
else
|
|
1708 |
{
|
|
1709 |
fail(regex_constants::error_badrepeat, m_position - m_base);
|
|
1710 |
return false;
|
|
1711 |
}
|
|
1712 |
++m_position;
|
|
1713 |
jump_offset = this->getoffset(this->append_state(syntax_element_jump, sizeof(re_jump)));
|
|
1714 |
this->append_state(syntax_element_backstep, sizeof(re_brace));
|
|
1715 |
this->m_pdata->m_data.align();
|
|
1716 |
m_alt_insert_point = this->m_pdata->m_data.size();
|
|
1717 |
break;
|
|
1718 |
}
|
|
1719 |
case regex_constants::escape_type_right_word:
|
|
1720 |
//
|
|
1721 |
// an independent sub-expression:
|
|
1722 |
//
|
|
1723 |
pb->index = markid = -3;
|
|
1724 |
++m_position;
|
|
1725 |
jump_offset = this->getoffset(this->append_state(syntax_element_jump, sizeof(re_jump)));
|
|
1726 |
this->m_pdata->m_data.align();
|
|
1727 |
m_alt_insert_point = this->m_pdata->m_data.size();
|
|
1728 |
break;
|
|
1729 |
case regex_constants::syntax_open_mark:
|
|
1730 |
{
|
|
1731 |
// a conditional expression:
|
|
1732 |
pb->index = markid = -4;
|
|
1733 |
if(++m_position == m_end)
|
|
1734 |
{
|
|
1735 |
fail(regex_constants::error_badrepeat, m_position - m_base);
|
|
1736 |
return false;
|
|
1737 |
}
|
|
1738 |
int v = this->m_traits.toi(m_position, m_end, 10);
|
|
1739 |
if(v > 0)
|
|
1740 |
{
|
|
1741 |
re_brace* br = static_cast<re_brace*>(this->append_state(syntax_element_assert_backref, sizeof(re_brace)));
|
|
1742 |
br->index = v;
|
|
1743 |
if(this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_mark)
|
|
1744 |
{
|
|
1745 |
fail(regex_constants::error_badrepeat, m_position - m_base);
|
|
1746 |
return false;
|
|
1747 |
}
|
|
1748 |
if(++m_position == m_end)
|
|
1749 |
{
|
|
1750 |
fail(regex_constants::error_badrepeat, m_position - m_base);
|
|
1751 |
return false;
|
|
1752 |
}
|
|
1753 |
}
|
|
1754 |
else
|
|
1755 |
{
|
|
1756 |
// verify that we have a lookahead or lookbehind assert:
|
|
1757 |
if(this->m_traits.syntax_type(*m_position) != regex_constants::syntax_question)
|
|
1758 |
{
|
|
1759 |
fail(regex_constants::error_badrepeat, m_position - m_base);
|
|
1760 |
return false;
|
|
1761 |
}
|
|
1762 |
if(++m_position == m_end)
|
|
1763 |
{
|
|
1764 |
fail(regex_constants::error_badrepeat, m_position - m_base);
|
|
1765 |
return false;
|
|
1766 |
}
|
|
1767 |
if(this->m_traits.syntax_type(*m_position) == regex_constants::escape_type_left_word)
|
|
1768 |
{
|
|
1769 |
if(++m_position == m_end)
|
|
1770 |
{
|
|
1771 |
fail(regex_constants::error_badrepeat, m_position - m_base);
|
|
1772 |
return false;
|
|
1773 |
}
|
|
1774 |
if((this->m_traits.syntax_type(*m_position) != regex_constants::syntax_equal)
|
|
1775 |
&& (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_not))
|
|
1776 |
{
|
|
1777 |
fail(regex_constants::error_badrepeat, m_position - m_base);
|
|
1778 |
return false;
|
|
1779 |
}
|
|
1780 |
m_position -= 3;
|
|
1781 |
}
|
|
1782 |
else
|
|
1783 |
{
|
|
1784 |
if((this->m_traits.syntax_type(*m_position) != regex_constants::syntax_equal)
|
|
1785 |
&& (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_not))
|
|
1786 |
{
|
|
1787 |
fail(regex_constants::error_badrepeat, m_position - m_base);
|
|
1788 |
return false;
|
|
1789 |
}
|
|
1790 |
m_position -= 2;
|
|
1791 |
}
|
|
1792 |
}
|
|
1793 |
break;
|
|
1794 |
}
|
|
1795 |
case regex_constants::syntax_close_mark:
|
|
1796 |
fail(regex_constants::error_badrepeat, m_position - m_base);
|
|
1797 |
return false;
|
|
1798 |
default:
|
|
1799 |
//
|
|
1800 |
// lets assume that we have a (?imsx) group and try and parse it:
|
|
1801 |
//
|
|
1802 |
regex_constants::syntax_option_type opts = parse_options();
|
|
1803 |
if(m_position == m_end)
|
|
1804 |
return false;
|
|
1805 |
// make a note of whether we have a case change:
|
|
1806 |
m_has_case_change = ((opts & regbase::icase) != (this->flags() & regbase::icase));
|
|
1807 |
pb->index = markid = 0;
|
|
1808 |
if(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_close_mark)
|
|
1809 |
{
|
|
1810 |
// update flags and carry on as normal:
|
|
1811 |
this->flags(opts);
|
|
1812 |
restore_flags = false;
|
|
1813 |
old_case_change |= m_has_case_change; // defer end of scope by one ')'
|
|
1814 |
}
|
|
1815 |
else if(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_colon)
|
|
1816 |
{
|
|
1817 |
// update flags and carry on until the matching ')' is found:
|
|
1818 |
this->flags(opts);
|
|
1819 |
++m_position;
|
|
1820 |
}
|
|
1821 |
else
|
|
1822 |
{
|
|
1823 |
fail(regex_constants::error_badrepeat, m_position - m_base);
|
|
1824 |
return false;
|
|
1825 |
}
|
|
1826 |
|
|
1827 |
// finally append a case change state if we need it:
|
|
1828 |
if(m_has_case_change)
|
|
1829 |
{
|
|
1830 |
static_cast<re_case*>(
|
|
1831 |
this->append_state(syntax_element_toggle_case, sizeof(re_case))
|
|
1832 |
)->icase = opts & regbase::icase;
|
|
1833 |
}
|
|
1834 |
|
|
1835 |
}
|
|
1836 |
//
|
|
1837 |
// now recursively add more states, this will terminate when we get to a
|
|
1838 |
// matching ')' :
|
|
1839 |
//
|
|
1840 |
parse_all();
|
|
1841 |
//
|
|
1842 |
// Unwind alternatives:
|
|
1843 |
//
|
|
1844 |
if(0 == unwind_alts(last_paren_start))
|
|
1845 |
return false;
|
|
1846 |
//
|
|
1847 |
// we either have a ')' or we have run out of characters prematurely:
|
|
1848 |
//
|
|
1849 |
if(m_position == m_end)
|
|
1850 |
{
|
|
1851 |
this->fail(regex_constants::error_paren, ::boost::re_detail::distance(m_base, m_end));
|
|
1852 |
return false;
|
|
1853 |
}
|
|
1854 |
BOOST_ASSERT(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_close_mark);
|
|
1855 |
++m_position;
|
|
1856 |
//
|
|
1857 |
// restore the flags:
|
|
1858 |
//
|
|
1859 |
if(restore_flags)
|
|
1860 |
{
|
|
1861 |
// append a case change state if we need it:
|
|
1862 |
if(m_has_case_change)
|
|
1863 |
{
|
|
1864 |
static_cast<re_case*>(
|
|
1865 |
this->append_state(syntax_element_toggle_case, sizeof(re_case))
|
|
1866 |
)->icase = old_flags & regbase::icase;
|
|
1867 |
}
|
|
1868 |
this->flags(old_flags);
|
|
1869 |
}
|
|
1870 |
//
|
|
1871 |
// set up the jump pointer if we have one:
|
|
1872 |
//
|
|
1873 |
if(jump_offset)
|
|
1874 |
{
|
|
1875 |
this->m_pdata->m_data.align();
|
|
1876 |
re_jump* jmp = static_cast<re_jump*>(this->getaddress(jump_offset));
|
|
1877 |
jmp->alt.i = this->m_pdata->m_data.size() - this->getoffset(jmp);
|
|
1878 |
if(this->m_last_state == jmp)
|
|
1879 |
{
|
|
1880 |
// Oops... we didn't have anything inside the assertion:
|
|
1881 |
fail(regex_constants::error_empty, m_position - m_base);
|
|
1882 |
return false;
|
|
1883 |
}
|
|
1884 |
}
|
|
1885 |
//
|
|
1886 |
// verify that if this is conditional expression, that we do have
|
|
1887 |
// an alternative, if not add one:
|
|
1888 |
//
|
|
1889 |
if(markid == -4)
|
|
1890 |
{
|
|
1891 |
re_syntax_base* b = this->getaddress(expected_alt_point);
|
|
1892 |
// Make sure we have exactly one alternative following this state:
|
|
1893 |
if(b->type != syntax_element_alt)
|
|
1894 |
{
|
|
1895 |
re_alt* alt = static_cast<re_alt*>(this->insert_state(expected_alt_point, syntax_element_alt, sizeof(re_alt)));
|
|
1896 |
alt->alt.i = this->m_pdata->m_data.size() - this->getoffset(alt);
|
|
1897 |
}
|
|
1898 |
else if(this->getaddress(static_cast<re_alt*>(b)->alt.i, b)->type == syntax_element_alt)
|
|
1899 |
{
|
|
1900 |
fail(regex_constants::error_bad_pattern, m_position - m_base);
|
|
1901 |
return false;
|
|
1902 |
}
|
|
1903 |
// check for invalid repetition of next state:
|
|
1904 |
b = this->getaddress(expected_alt_point);
|
|
1905 |
b = this->getaddress(static_cast<re_alt*>(b)->next.i, b);
|
|
1906 |
if((b->type != syntax_element_assert_backref)
|
|
1907 |
&& (b->type != syntax_element_startmark))
|
|
1908 |
{
|
|
1909 |
fail(regex_constants::error_badrepeat, m_position - m_base);
|
|
1910 |
return false;
|
|
1911 |
}
|
|
1912 |
}
|
|
1913 |
//
|
|
1914 |
// append closing parenthesis state:
|
|
1915 |
//
|
|
1916 |
pb = static_cast<re_brace*>(this->append_state(syntax_element_endmark, sizeof(re_brace)));
|
|
1917 |
pb->index = markid;
|
|
1918 |
this->m_paren_start = last_paren_start;
|
|
1919 |
//
|
|
1920 |
// restore the alternate insertion point:
|
|
1921 |
//
|
|
1922 |
this->m_alt_insert_point = last_alt_point;
|
|
1923 |
//
|
|
1924 |
// and the case change data:
|
|
1925 |
//
|
|
1926 |
m_has_case_change = old_case_change;
|
|
1927 |
return true;
|
|
1928 |
}
|
|
1929 |
|
|
1930 |
template <class charT, class traits>
|
|
1931 |
bool basic_regex_parser<charT, traits>::add_emacs_code(bool negate)
|
|
1932 |
{
|
|
1933 |
//
|
|
1934 |
// parses an emacs style \sx or \Sx construct.
|
|
1935 |
//
|
|
1936 |
if(++m_position == m_end)
|
|
1937 |
{
|
|
1938 |
fail(regex_constants::error_escape, m_position - m_base);
|
|
1939 |
return false;
|
|
1940 |
}
|
|
1941 |
basic_char_set<charT, traits> char_set;
|
|
1942 |
if(negate)
|
|
1943 |
char_set.negate();
|
|
1944 |
|
|
1945 |
static const charT s_punct[5] = { 'p', 'u', 'n', 'c', 't', };
|
|
1946 |
|
|
1947 |
switch(*m_position)
|
|
1948 |
{
|
|
1949 |
case 's':
|
|
1950 |
case ' ':
|
|
1951 |
char_set.add_class(this->m_mask_space);
|
|
1952 |
break;
|
|
1953 |
case 'w':
|
|
1954 |
char_set.add_class(this->m_word_mask);
|
|
1955 |
break;
|
|
1956 |
case '_':
|
|
1957 |
char_set.add_single(digraph<charT>(charT('$')));
|
|
1958 |
char_set.add_single(digraph<charT>(charT('&')));
|
|
1959 |
char_set.add_single(digraph<charT>(charT('*')));
|
|
1960 |
char_set.add_single(digraph<charT>(charT('+')));
|
|
1961 |
char_set.add_single(digraph<charT>(charT('-')));
|
|
1962 |
char_set.add_single(digraph<charT>(charT('_')));
|
|
1963 |
char_set.add_single(digraph<charT>(charT('<')));
|
|
1964 |
char_set.add_single(digraph<charT>(charT('>')));
|
|
1965 |
break;
|
|
1966 |
case '.':
|
|
1967 |
char_set.add_class(this->m_traits.lookup_classname(s_punct, s_punct+5));
|
|
1968 |
break;
|
|
1969 |
case '(':
|
|
1970 |
char_set.add_single(digraph<charT>(charT('(')));
|
|
1971 |
char_set.add_single(digraph<charT>(charT('[')));
|
|
1972 |
char_set.add_single(digraph<charT>(charT('{')));
|
|
1973 |
break;
|
|
1974 |
case ')':
|
|
1975 |
char_set.add_single(digraph<charT>(charT(')')));
|
|
1976 |
char_set.add_single(digraph<charT>(charT(']')));
|
|
1977 |
char_set.add_single(digraph<charT>(charT('}')));
|
|
1978 |
break;
|
|
1979 |
case '"':
|
|
1980 |
char_set.add_single(digraph<charT>(charT('"')));
|
|
1981 |
char_set.add_single(digraph<charT>(charT('\'')));
|
|
1982 |
char_set.add_single(digraph<charT>(charT('`')));
|
|
1983 |
break;
|
|
1984 |
case '\'':
|
|
1985 |
char_set.add_single(digraph<charT>(charT('\'')));
|
|
1986 |
char_set.add_single(digraph<charT>(charT(',')));
|
|
1987 |
char_set.add_single(digraph<charT>(charT('#')));
|
|
1988 |
break;
|
|
1989 |
case '<':
|
|
1990 |
char_set.add_single(digraph<charT>(charT(';')));
|
|
1991 |
break;
|
|
1992 |
case '>':
|
|
1993 |
char_set.add_single(digraph<charT>(charT('\n')));
|
|
1994 |
char_set.add_single(digraph<charT>(charT('\f')));
|
|
1995 |
break;
|
|
1996 |
default:
|
|
1997 |
fail(regex_constants::error_ctype, m_position - m_base);
|
|
1998 |
return false;
|
|
1999 |
}
|
|
2000 |
if(0 == this->append_set(char_set))
|
|
2001 |
{
|
|
2002 |
fail(regex_constants::error_ctype, m_position - m_base);
|
|
2003 |
return false;
|
|
2004 |
}
|
|
2005 |
++m_position;
|
|
2006 |
return true;
|
|
2007 |
}
|
|
2008 |
|
|
2009 |
template <class charT, class traits>
|
|
2010 |
regex_constants::syntax_option_type basic_regex_parser<charT, traits>::parse_options()
|
|
2011 |
{
|
|
2012 |
// we have a (?imsx-imsx) group, convert it into a set of flags:
|
|
2013 |
regex_constants::syntax_option_type f = this->flags();
|
|
2014 |
bool breakout = false;
|
|
2015 |
do
|
|
2016 |
{
|
|
2017 |
switch(*m_position)
|
|
2018 |
{
|
|
2019 |
case 's':
|
|
2020 |
f |= regex_constants::mod_s;
|
|
2021 |
f &= ~regex_constants::no_mod_s;
|
|
2022 |
break;
|
|
2023 |
case 'm':
|
|
2024 |
f &= ~regex_constants::no_mod_m;
|
|
2025 |
break;
|
|
2026 |
case 'i':
|
|
2027 |
f |= regex_constants::icase;
|
|
2028 |
break;
|
|
2029 |
case 'x':
|
|
2030 |
f |= regex_constants::mod_x;
|
|
2031 |
break;
|
|
2032 |
default:
|
|
2033 |
breakout = true;
|
|
2034 |
continue;
|
|
2035 |
}
|
|
2036 |
if(++m_position == m_end)
|
|
2037 |
{
|
|
2038 |
fail(regex_constants::error_paren, m_position - m_base);
|
|
2039 |
return false;
|
|
2040 |
}
|
|
2041 |
}
|
|
2042 |
while(!breakout);
|
|
2043 |
|
|
2044 |
if(*m_position == static_cast<charT>('-'))
|
|
2045 |
{
|
|
2046 |
if(++m_position == m_end)
|
|
2047 |
{
|
|
2048 |
fail(regex_constants::error_paren, m_position - m_base);
|
|
2049 |
return false;
|
|
2050 |
}
|
|
2051 |
do
|
|
2052 |
{
|
|
2053 |
switch(*m_position)
|
|
2054 |
{
|
|
2055 |
case 's':
|
|
2056 |
f &= ~regex_constants::mod_s;
|
|
2057 |
f |= regex_constants::no_mod_s;
|
|
2058 |
break;
|
|
2059 |
case 'm':
|
|
2060 |
f |= regex_constants::no_mod_m;
|
|
2061 |
break;
|
|
2062 |
case 'i':
|
|
2063 |
f &= ~regex_constants::icase;
|
|
2064 |
break;
|
|
2065 |
case 'x':
|
|
2066 |
f &= ~regex_constants::mod_x;
|
|
2067 |
break;
|
|
2068 |
default:
|
|
2069 |
breakout = true;
|
|
2070 |
continue;
|
|
2071 |
}
|
|
2072 |
if(++m_position == m_end)
|
|
2073 |
{
|
|
2074 |
fail(regex_constants::error_paren, m_position - m_base);
|
|
2075 |
return false;
|
|
2076 |
}
|
|
2077 |
}
|
|
2078 |
while(!breakout);
|
|
2079 |
}
|
|
2080 |
return f;
|
|
2081 |
}
|
|
2082 |
|
|
2083 |
template <class charT, class traits>
|
|
2084 |
bool basic_regex_parser<charT, traits>::unwind_alts(std::ptrdiff_t last_paren_start)
|
|
2085 |
{
|
|
2086 |
//
|
|
2087 |
// If we didn't actually add any states after the last
|
|
2088 |
// alternative then that's an error:
|
|
2089 |
//
|
|
2090 |
if((this->m_alt_insert_point == static_cast<std::ptrdiff_t>(this->m_pdata->m_data.size()))
|
|
2091 |
&& m_alt_jumps.size() && (m_alt_jumps.back() > last_paren_start)
|
|
2092 |
&&
|
|
2093 |
!(
|
|
2094 |
((this->flags() & regbase::main_option_type) == regbase::perl_syntax_group)
|
|
2095 |
&&
|
|
2096 |
((this->flags() & regbase::no_empty_expressions) == 0)
|
|
2097 |
)
|
|
2098 |
)
|
|
2099 |
{
|
|
2100 |
fail(regex_constants::error_empty, this->m_position - this->m_base);
|
|
2101 |
return false;
|
|
2102 |
}
|
|
2103 |
//
|
|
2104 |
// Fix up our alternatives:
|
|
2105 |
//
|
|
2106 |
while(m_alt_jumps.size() && (m_alt_jumps.back() > last_paren_start))
|
|
2107 |
{
|
|
2108 |
//
|
|
2109 |
// fix up the jump to point to the end of the states
|
|
2110 |
// that we've just added:
|
|
2111 |
//
|
|
2112 |
std::ptrdiff_t jump_offset = m_alt_jumps.back();
|
|
2113 |
m_alt_jumps.pop_back();
|
|
2114 |
this->m_pdata->m_data.align();
|
|
2115 |
re_jump* jmp = static_cast<re_jump*>(this->getaddress(jump_offset));
|
|
2116 |
BOOST_ASSERT(jmp->type == syntax_element_jump);
|
|
2117 |
jmp->alt.i = this->m_pdata->m_data.size() - jump_offset;
|
|
2118 |
}
|
|
2119 |
return true;
|
|
2120 |
}
|
|
2121 |
|
|
2122 |
#ifdef BOOST_MSVC
|
|
2123 |
#pragma warning(pop)
|
|
2124 |
#endif
|
|
2125 |
|
|
2126 |
} // namespace re_detail
|
|
2127 |
} // namespace boost
|
|
2128 |
|
|
2129 |
#ifdef BOOST_MSVC
|
|
2130 |
#pragma warning(push)
|
|
2131 |
#pragma warning(disable: 4103)
|
|
2132 |
#endif
|
|
2133 |
#ifdef BOOST_HAS_ABI_HEADERS
|
|
2134 |
# include BOOST_ABI_SUFFIX
|
|
2135 |
#endif
|
|
2136 |
#ifdef BOOST_MSVC
|
|
2137 |
#pragma warning(pop)
|
|
2138 |
#endif
|
|
2139 |
|
|
2140 |
#endif
|