1 ///////////////////////////////////////////////////////////////////////////////
2 /// \file regex_primitives.hpp
3 /// Contains the syntax elements for writing static regular expressions.
5 // Copyright 2008 Eric Niebler. Distributed under the Boost
6 // Software License, Version 1.0. (See accompanying file
7 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 #ifndef BOOST_XPRESSIVE_REGEX_PRIMITIVES_HPP_EAN_10_04_2005
10 #define BOOST_XPRESSIVE_REGEX_PRIMITIVES_HPP_EAN_10_04_2005
14 #include <boost/config.hpp>
15 #include <boost/assert.hpp>
16 #include <boost/mpl/if.hpp>
17 #include <boost/mpl/and.hpp>
18 #include <boost/mpl/assert.hpp>
19 #include <boost/detail/workaround.hpp>
20 #include <boost/preprocessor/cat.hpp>
21 #include <boost/xpressive/detail/detail_fwd.hpp>
22 #include <boost/xpressive/detail/core/matchers.hpp>
23 #include <boost/xpressive/detail/utility/ignore_unused.hpp>
25 // Doxygen can't handle proto :-(
26 #ifndef BOOST_XPRESSIVE_DOXYGEN_INVOKED
27 # include <boost/proto/core.hpp>
28 # include <boost/proto/transform/arg.hpp>
29 # include <boost/proto/transform/when.hpp>
30 # include <boost/xpressive/detail/core/icase.hpp>
31 # include <boost/xpressive/detail/static/compile.hpp>
32 # include <boost/xpressive/detail/static/modifier.hpp>
35 namespace boost
{ namespace xpressive
{ namespace detail
38 typedef assert_word_placeholder
<word_boundary
<mpl::true_
> > assert_word_boundary
;
39 typedef assert_word_placeholder
<word_begin
> assert_word_begin
;
40 typedef assert_word_placeholder
<word_end
> assert_word_end
;
43 : proto::extends
<basic_mark_tag
, mark_tag
>
45 mark_tag(int mark_nbr
)
47 // Marks numbers must be integers greater than 0.
48 BOOST_ASSERT(mark_nbr
> 0);
49 mark_placeholder mark
= {mark_nbr
};
50 proto::value(*this) = mark
;
53 operator basic_mark_tag
const &() const
55 return this->proto_base();
58 using proto::extends
<basic_mark_tag
, mark_tag
>::operator =;
61 // workaround msvc-7.1 bug with function pointer types
62 // within function types:
63 #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
64 #define mark_number(x) proto::call<mark_number(x)>
65 #define minus_one() proto::make<minus_one()>
68 struct push_back
: proto::callable
70 typedef int result_type
;
72 template<typename Subs
>
73 int operator ()(Subs
&subs
, int i
) const
80 struct mark_number
: proto::callable
82 typedef int result_type
;
84 template<typename Expr
>
85 int operator ()(Expr
const &expr
) const
87 return expr
.mark_number_
;
91 typedef mpl::int_
<-1> minus_one
;
96 proto::when
<basic_mark_tag
, push_back(proto::_data
, mark_number(proto::_value
)) >
97 , proto::when
<proto::negate
<basic_mark_tag
>, push_back(proto::_data
, minus_one()) >
102 : proto::or_
<SubMatch
, proto::comma
<SubMatchList
, SubMatch
> >
105 template<typename Subs
>
107 mpl::and_
<proto::is_expr
<Subs
>, proto::matches
<Subs
, SubMatchList
> >
110 to_vector(Subs
const &subs
)
112 std::vector
<int> subs_
;
113 SubMatchList()(subs
, 0, subs_
);
117 #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
122 // replace "Expr" with "keep(*State) >> Expr"
123 struct skip_primitives
: proto::transform
<skip_primitives
>
125 template<typename Expr
, typename State
, typename Data
>
126 struct impl
: proto::transform_impl
<Expr
, State
, Data
>
129 typename
proto::shift_right
<
130 typename
proto::unary_expr
<
132 , typename
proto::dereference
<State
>::type
138 result_type
operator ()(
139 typename
impl::expr_param expr
140 , typename
impl::state_param state
141 , typename
impl::data_param
144 result_type that
= {{{state
}}, expr
};
152 proto::terminal
<proto::_
>
153 , proto::comma
<proto::_
, proto::_
>
154 , proto::subscript
<proto::terminal
<set_initializer
>, proto::_
>
155 , proto::assign
<proto::terminal
<set_initializer
>, proto::_
>
156 , proto::assign
<proto::terminal
<attribute_placeholder
<proto::_
> >, proto::_
>
157 , proto::complement
<Primitives
>
163 proto::when
<Primitives
, skip_primitives
>
164 , proto::assign
<proto::terminal
<mark_placeholder
>, SkipGrammar
> // don't "skip" mark tags
165 , proto::subscript
<SkipGrammar
, proto::_
> // don't put skips in actions
166 , proto::binary_expr
<modifier_tag
, proto::_
, SkipGrammar
> // don't skip modifiers
167 , proto::unary_expr
<lookbehind_tag
, proto::_
> // don't skip lookbehinds
168 , proto::nary_expr
<proto::_
, proto::vararg
<SkipGrammar
> > // everything else is fair game!
172 template<typename Skip
>
173 struct skip_directive
175 typedef typename
proto::result_of::as_expr
<Skip
>::type skip_type
;
177 skip_directive(Skip
const &skip
)
178 : skip_(proto::as_expr(skip
))
181 template<typename Sig
>
184 template<typename This
, typename Expr
>
185 struct result
<This(Expr
)>
189 typename
proto::result_of::as_expr
<Expr
>::type
196 typename
proto::shift_right
<
197 typename
skip_transform::result_type
198 , typename
proto::dereference
<skip_type
>::type
203 template<typename Expr
>
204 typename result
<skip_directive(Expr
)>::type
205 operator ()(Expr
const &expr
) const
208 typedef result
<skip_directive(Expr
)> result_fun
;
209 typename
result_fun::type that
= {
210 typename
result_fun::skip_transform()(proto::as_expr(expr
), this->skip_
, ignore
)
221 ///////////////////////////////////////////////////////////////////////////////
223 // BOOST_XPRESSIVE_GLOBAL
224 // for defining globals that neither violate the One Definition Rule nor
225 // lead to undefined behavior due to global object initialization order.
226 //#define BOOST_XPRESSIVE_GLOBAL(type, name, init) \
227 // namespace detail \
229 // template<int Dummy> \
230 // struct BOOST_PP_CAT(global_pod_, name) \
232 // static type const value; \
234 // union type_must_be_pod \
240 // template<int Dummy> \
241 // type const BOOST_PP_CAT(global_pod_, name)<Dummy>::value = init; \
243 // type const &name = detail::BOOST_PP_CAT(global_pod_, name)<0>::value
247 } // namespace detail
249 /// INTERNAL ONLY (for backwards compatibility)
250 unsigned int const repeat_max
= UINT_MAX
-1;
252 ///////////////////////////////////////////////////////////////////////////////
253 /// \brief For infinite repetition of a sub-expression.
255 /// Magic value used with the repeat\<\>() function template
256 /// to specify an unbounded repeat. Use as: repeat<17, inf>('a').
257 /// The equivalent in perl is /a{17,}/.
258 unsigned int const inf
= UINT_MAX
-1;
260 /// INTERNAL ONLY (for backwards compatibility)
261 proto::terminal
<detail::epsilon_matcher
>::type
const epsilon
= {{}};
263 ///////////////////////////////////////////////////////////////////////////////
264 /// \brief Successfully matches nothing.
266 /// Successfully matches a zero-width sequence. nil always succeeds and
267 /// never consumes any characters.
268 proto::terminal
<detail::epsilon_matcher
>::type
const nil
= {{}};
270 ///////////////////////////////////////////////////////////////////////////////
271 /// \brief Matches an alpha-numeric character.
273 /// The regex traits are used to determine which characters are alpha-numeric.
274 /// To match any character that is not alpha-numeric, use ~alnum.
276 /// \attention alnum is equivalent to /[[:alnum:]]/ in perl. ~alnum is equivalent
277 /// to /[[:^alnum:]]/ in perl.
278 proto::terminal
<detail::posix_charset_placeholder
>::type
const alnum
= {{"alnum", false}};
280 ///////////////////////////////////////////////////////////////////////////////
281 /// \brief Matches an alphabetic character.
283 /// The regex traits are used to determine which characters are alphabetic.
284 /// To match any character that is not alphabetic, use ~alpha.
286 /// \attention alpha is equivalent to /[[:alpha:]]/ in perl. ~alpha is equivalent
287 /// to /[[:^alpha:]]/ in perl.
288 proto::terminal
<detail::posix_charset_placeholder
>::type
const alpha
= {{"alpha", false}};
290 ///////////////////////////////////////////////////////////////////////////////
291 /// \brief Matches a blank (horizonal white-space) character.
293 /// The regex traits are used to determine which characters are blank characters.
294 /// To match any character that is not blank, use ~blank.
296 /// \attention blank is equivalent to /[[:blank:]]/ in perl. ~blank is equivalent
297 /// to /[[:^blank:]]/ in perl.
298 proto::terminal
<detail::posix_charset_placeholder
>::type
const blank
= {{"blank", false}};
300 ///////////////////////////////////////////////////////////////////////////////
301 /// \brief Matches a control character.
303 /// The regex traits are used to determine which characters are control characters.
304 /// To match any character that is not a control character, use ~cntrl.
306 /// \attention cntrl is equivalent to /[[:cntrl:]]/ in perl. ~cntrl is equivalent
307 /// to /[[:^cntrl:]]/ in perl.
308 proto::terminal
<detail::posix_charset_placeholder
>::type
const cntrl
= {{"cntrl", false}};
310 ///////////////////////////////////////////////////////////////////////////////
311 /// \brief Matches a digit character.
313 /// The regex traits are used to determine which characters are digits.
314 /// To match any character that is not a digit, use ~digit.
316 /// \attention digit is equivalent to /[[:digit:]]/ in perl. ~digit is equivalent
317 /// to /[[:^digit:]]/ in perl.
318 proto::terminal
<detail::posix_charset_placeholder
>::type
const digit
= {{"digit", false}};
320 ///////////////////////////////////////////////////////////////////////////////
321 /// \brief Matches a graph character.
323 /// The regex traits are used to determine which characters are graphable.
324 /// To match any character that is not graphable, use ~graph.
326 /// \attention graph is equivalent to /[[:graph:]]/ in perl. ~graph is equivalent
327 /// to /[[:^graph:]]/ in perl.
328 proto::terminal
<detail::posix_charset_placeholder
>::type
const graph
= {{"graph", false}};
330 ///////////////////////////////////////////////////////////////////////////////
331 /// \brief Matches a lower-case character.
333 /// The regex traits are used to determine which characters are lower-case.
334 /// To match any character that is not a lower-case character, use ~lower.
336 /// \attention lower is equivalent to /[[:lower:]]/ in perl. ~lower is equivalent
337 /// to /[[:^lower:]]/ in perl.
338 proto::terminal
<detail::posix_charset_placeholder
>::type
const lower
= {{"lower", false}};
340 ///////////////////////////////////////////////////////////////////////////////
341 /// \brief Matches a printable character.
343 /// The regex traits are used to determine which characters are printable.
344 /// To match any character that is not printable, use ~print.
346 /// \attention print is equivalent to /[[:print:]]/ in perl. ~print is equivalent
347 /// to /[[:^print:]]/ in perl.
348 proto::terminal
<detail::posix_charset_placeholder
>::type
const print
= {{"print", false}};
350 ///////////////////////////////////////////////////////////////////////////////
351 /// \brief Matches a punctuation character.
353 /// The regex traits are used to determine which characters are punctuation.
354 /// To match any character that is not punctuation, use ~punct.
356 /// \attention punct is equivalent to /[[:punct:]]/ in perl. ~punct is equivalent
357 /// to /[[:^punct:]]/ in perl.
358 proto::terminal
<detail::posix_charset_placeholder
>::type
const punct
= {{"punct", false}};
360 ///////////////////////////////////////////////////////////////////////////////
361 /// \brief Matches a space character.
363 /// The regex traits are used to determine which characters are space characters.
364 /// To match any character that is not white-space, use ~space.
366 /// \attention space is equivalent to /[[:space:]]/ in perl. ~space is equivalent
367 /// to /[[:^space:]]/ in perl.
368 proto::terminal
<detail::posix_charset_placeholder
>::type
const space
= {{"space", false}};
370 ///////////////////////////////////////////////////////////////////////////////
371 /// \brief Matches an upper-case character.
373 /// The regex traits are used to determine which characters are upper-case.
374 /// To match any character that is not upper-case, use ~upper.
376 /// \attention upper is equivalent to /[[:upper:]]/ in perl. ~upper is equivalent
377 /// to /[[:^upper:]]/ in perl.
378 proto::terminal
<detail::posix_charset_placeholder
>::type
const upper
= {{"upper", false}};
380 ///////////////////////////////////////////////////////////////////////////////
381 /// \brief Matches a hexadecimal digit character.
383 /// The regex traits are used to determine which characters are hex digits.
384 /// To match any character that is not a hex digit, use ~xdigit.
386 /// \attention xdigit is equivalent to /[[:xdigit:]]/ in perl. ~xdigit is equivalent
387 /// to /[[:^xdigit:]]/ in perl.
388 proto::terminal
<detail::posix_charset_placeholder
>::type
const xdigit
= {{"xdigit", false}};
390 ///////////////////////////////////////////////////////////////////////////////
391 /// \brief Beginning of sequence assertion.
393 /// For the character sequence [begin, end), 'bos' matches the
394 /// zero-width sub-sequence [begin, begin).
395 proto::terminal
<detail::assert_bos_matcher
>::type
const bos
= {{}};
397 ///////////////////////////////////////////////////////////////////////////////
398 /// \brief End of sequence assertion.
400 /// For the character sequence [begin, end),
401 /// 'eos' matches the zero-width sub-sequence [end, end).
403 /// \attention Unlike the perl end of sequence assertion \$, 'eos' will
404 /// not match at the position [end-1, end-1) if *(end-1) is '\\n'. To
405 /// get that behavior, use (!_n >> eos).
406 proto::terminal
<detail::assert_eos_matcher
>::type
const eos
= {{}};
408 ///////////////////////////////////////////////////////////////////////////////
409 /// \brief Beginning of line assertion.
411 /// 'bol' matches the zero-width sub-sequence
412 /// immediately following a logical newline sequence. The regex traits
413 /// is used to determine what constitutes a logical newline sequence.
414 proto::terminal
<detail::assert_bol_placeholder
>::type
const bol
= {{}};
416 ///////////////////////////////////////////////////////////////////////////////
417 /// \brief End of line assertion.
419 /// 'eol' matches the zero-width sub-sequence
420 /// immediately preceeding a logical newline sequence. The regex traits
421 /// is used to determine what constitutes a logical newline sequence.
422 proto::terminal
<detail::assert_eol_placeholder
>::type
const eol
= {{}};
424 ///////////////////////////////////////////////////////////////////////////////
425 /// \brief Beginning of word assertion.
427 /// 'bow' matches the zero-width sub-sequence
428 /// immediately following a non-word character and preceeding a word character.
429 /// The regex traits are used to determine what constitutes a word character.
430 proto::terminal
<detail::assert_word_begin
>::type
const bow
= {{}};
432 ///////////////////////////////////////////////////////////////////////////////
433 /// \brief End of word assertion.
435 /// 'eow' matches the zero-width sub-sequence
436 /// immediately following a word character and preceeding a non-word character.
437 /// The regex traits are used to determine what constitutes a word character.
438 proto::terminal
<detail::assert_word_end
>::type
const eow
= {{}};
440 ///////////////////////////////////////////////////////////////////////////////
441 /// \brief Word boundary assertion.
443 /// '_b' matches the zero-width sub-sequence at the beginning or the end of a word.
444 /// It is equivalent to (bow | eow). The regex traits are used to determine what
445 /// constitutes a word character. To match a non-word boundary, use ~_b.
447 /// \attention _b is like \\b in perl. ~_b is like \\B in perl.
448 proto::terminal
<detail::assert_word_boundary
>::type
const _b
= {{}};
450 ///////////////////////////////////////////////////////////////////////////////
451 /// \brief Matches a word character.
453 /// '_w' matches a single word character. The regex traits are used to determine which
454 /// characters are word characters. Use ~_w to match a character that is not a word
457 /// \attention _w is like \\w in perl. ~_w is like \\W in perl.
458 proto::terminal
<detail::posix_charset_placeholder
>::type
const _w
= {{"w", false}};
460 ///////////////////////////////////////////////////////////////////////////////
461 /// \brief Matches a digit character.
463 /// '_d' matches a single digit character. The regex traits are used to determine which
464 /// characters are digits. Use ~_d to match a character that is not a digit
467 /// \attention _d is like \\d in perl. ~_d is like \\D in perl.
468 proto::terminal
<detail::posix_charset_placeholder
>::type
const _d
= {{"d", false}};
470 ///////////////////////////////////////////////////////////////////////////////
471 /// \brief Matches a space character.
473 /// '_s' matches a single space character. The regex traits are used to determine which
474 /// characters are space characters. Use ~_s to match a character that is not a space
477 /// \attention _s is like \\s in perl. ~_s is like \\S in perl.
478 proto::terminal
<detail::posix_charset_placeholder
>::type
const _s
= {{"s", false}};
480 ///////////////////////////////////////////////////////////////////////////////
481 /// \brief Matches a literal newline character, '\\n'.
483 /// '_n' matches a single newline character, '\\n'. Use ~_n to match a character
484 /// that is not a newline.
486 /// \attention ~_n is like '.' in perl without the /s modifier.
487 proto::terminal
<char>::type
const _n
= {'\n'};
489 ///////////////////////////////////////////////////////////////////////////////
490 /// \brief Matches a logical newline sequence.
492 /// '_ln' matches a logical newline sequence. This can be any character in the
493 /// line separator class, as determined by the regex traits, or the '\\r\\n' sequence.
494 /// For the purpose of back-tracking, '\\r\\n' is treated as a unit.
495 /// To match any one character that is not a logical newline, use ~_ln.
496 detail::logical_newline_xpression
const _ln
= {{}};
498 ///////////////////////////////////////////////////////////////////////////////
499 /// \brief Matches any one character.
501 /// Match any character, similar to '.' in perl syntax with the /s modifier.
502 /// '_' matches any one character, including the newline.
504 /// \attention To match any character except the newline, use ~_n
505 proto::terminal
<detail::any_matcher
>::type
const _
= {{}};
507 ///////////////////////////////////////////////////////////////////////////////
508 /// \brief Reference to the current regex object
510 /// Useful when constructing recursive regular expression objects. The 'self'
511 /// identifier is a short-hand for the current regex object. For instance,
512 /// sregex rx = '(' >> (self | nil) >> ')'; will create a regex object that
513 /// matches balanced parens such as "((()))".
514 proto::terminal
<detail::self_placeholder
>::type
const self
= {{}};
516 ///////////////////////////////////////////////////////////////////////////////
517 /// \brief Used to create character sets.
519 /// There are two ways to create character sets with the 'set' identifier. The
520 /// easiest is to create a comma-separated list of the characters in the set,
521 /// as in (set= 'a','b','c'). This set will match 'a', 'b', or 'c'. The other
522 /// way is to define the set as an argument to the set subscript operator.
523 /// For instance, set[ 'a' | range('b','c') | digit ] will match an 'a', 'b',
524 /// 'c' or a digit character.
526 /// To complement a set, apply the '~' operator. For instance, ~(set= 'a','b','c')
527 /// will match any character that is not an 'a', 'b', or 'c'.
529 /// Sets can be composed of other, possibly complemented, sets. For instance,
530 /// set[ ~digit | ~(set= 'a','b','c') ].
531 detail::set_initializer_type
const set
= {{}};
533 ///////////////////////////////////////////////////////////////////////////////
534 /// \brief Sub-match placeholder, like $& in Perl
535 mark_tag::proto_base_expr
const s0
= {{0}};
537 ///////////////////////////////////////////////////////////////////////////////
538 /// \brief Sub-match placeholder, like $1 in perl.
540 /// To create a sub-match, assign a sub-expression to the sub-match placeholder.
541 /// For instance, (s1= _) will match any one character and remember which
542 /// character was matched in the 1st sub-match. Later in the pattern, you can
543 /// refer back to the sub-match. For instance, (s1= _) >> s1 will match any
544 /// character, and then match the same character again.
546 /// After a successful regex_match() or regex_search(), the sub-match placeholders
547 /// can be used to index into the match_results\<\> object to retrieve the Nth
549 mark_tag::proto_base_expr
const s1
= {{1}};
550 mark_tag::proto_base_expr
const s2
= {{2}};
551 mark_tag::proto_base_expr
const s3
= {{3}};
552 mark_tag::proto_base_expr
const s4
= {{4}};
553 mark_tag::proto_base_expr
const s5
= {{5}};
554 mark_tag::proto_base_expr
const s6
= {{6}};
555 mark_tag::proto_base_expr
const s7
= {{7}};
556 mark_tag::proto_base_expr
const s8
= {{8}};
557 mark_tag::proto_base_expr
const s9
= {{9}};
559 // NOTE: For the purpose of xpressive's documentation, make icase() look like an
560 // ordinary function. In reality, it is a function object defined in detail/icase.hpp
561 // so that it can serve double-duty as regex_constants::icase, the syntax_option_type.
562 #ifdef BOOST_XPRESSIVE_DOXYGEN_INVOKED
563 ///////////////////////////////////////////////////////////////////////////////
564 /// \brief Makes a sub-expression case-insensitive.
566 /// Use icase() to make a sub-expression case-insensitive. For instance,
567 /// "foo" >> icase(set['b'] >> "ar") will match "foo" exactly followed by
568 /// "bar" irrespective of case.
569 template<typename Expr
> detail::unspecified
icase(Expr
const &expr
) { return 0; }
572 ///////////////////////////////////////////////////////////////////////////////
573 /// \brief Makes a literal into a regular expression.
575 /// Use as_xpr() to turn a literal into a regular expression. For instance,
576 /// "foo" >> "bar" will not compile because both operands to the right-shift
577 /// operator are const char*, and no such operator exists. Use as_xpr("foo") >> "bar"
580 /// You can use as_xpr() with character literals in addition to string literals.
581 /// For instance, as_xpr('a') will match an 'a'. You can also complement a
582 /// character literal, as with ~as_xpr('a'). This will match any one character
583 /// that is not an 'a'.
584 #ifdef BOOST_XPRESSIVE_DOXYGEN_INVOKED
585 template<typename Literal
> detail::unspecified
as_xpr(Literal
const &literal
) { return 0; }
587 proto::functional::as_expr
<> const as_xpr
= {};
590 ///////////////////////////////////////////////////////////////////////////////
591 /// \brief Embed a regex object by reference.
593 /// \param rex The basic_regex object to embed by reference.
594 template<typename BidiIter
>
595 inline typename
proto::terminal
<reference_wrapper
<basic_regex
<BidiIter
> const> >::type
const
596 by_ref(basic_regex
<BidiIter
> const &rex
)
598 reference_wrapper
<basic_regex
<BidiIter
> const> ref(rex
);
599 return proto::terminal
<reference_wrapper
<basic_regex
<BidiIter
> const> >::type::make(ref
);
602 ///////////////////////////////////////////////////////////////////////////////
603 /// \brief Match a range of characters.
605 /// Match any character in the range [ch_min, ch_max].
607 /// \param ch_min The lower end of the range to match.
608 /// \param ch_max The upper end of the range to match.
609 template<typename Char
>
610 inline typename
proto::terminal
<detail::range_placeholder
<Char
> >::type
const
611 range(Char ch_min
, Char ch_max
)
613 detail::range_placeholder
<Char
> that
= {ch_min
, ch_max
, false};
614 return proto::terminal
<detail::range_placeholder
<Char
> >::type::make(that
);
617 ///////////////////////////////////////////////////////////////////////////////
618 /// \brief Make a sub-expression optional. Equivalent to !as_xpr(expr).
620 /// \param expr The sub-expression to make optional.
621 template<typename Expr
>
622 typename
proto::result_of::make_expr
<
623 proto::tag::logical_not
624 , proto::default_domain
627 optional(Expr
const &expr
)
629 return proto::make_expr
<
630 proto::tag::logical_not
631 , proto::default_domain
635 ///////////////////////////////////////////////////////////////////////////////
636 /// \brief Repeat a sub-expression multiple times.
638 /// There are two forms of the repeat\<\>() function template. To match a
639 /// sub-expression N times, use repeat\<N\>(expr). To match a sub-expression
640 /// from M to N times, use repeat\<M,N\>(expr).
642 /// The repeat\<\>() function creates a greedy quantifier. To make the quantifier
643 /// non-greedy, apply the unary minus operator, as in -repeat\<M,N\>(expr).
645 /// \param expr The sub-expression to repeat.
646 template<unsigned int Min
, unsigned int Max
, typename Expr
>
647 typename
proto::result_of::make_expr
<
648 detail::generic_quant_tag
<Min
, Max
>
649 , proto::default_domain
652 repeat(Expr
const &expr
)
654 return proto::make_expr
<
655 detail::generic_quant_tag
<Min
, Max
>
656 , proto::default_domain
662 template<unsigned int Count
, typename Expr2
>
663 typename
proto::result_of::make_expr
<
664 detail::generic_quant_tag
<Count
, Count
>
665 , proto::default_domain
668 repeat(Expr2
const &expr2
)
670 return proto::make_expr
<
671 detail::generic_quant_tag
<Count
, Count
>
672 , proto::default_domain
673 >(boost::ref(expr2
));
676 ///////////////////////////////////////////////////////////////////////////////
677 /// \brief Create an independent sub-expression.
679 /// Turn off back-tracking for a sub-expression. Any branches or repeats within
680 /// the sub-expression will match only one way, and no other alternatives are
683 /// \attention keep(expr) is equivalent to the perl (?>...) extension.
685 /// \param expr The sub-expression to modify.
686 template<typename Expr
>
687 typename
proto::result_of::make_expr
<
689 , proto::default_domain
692 keep(Expr
const &expr
)
694 return proto::make_expr
<
696 , proto::default_domain
700 ///////////////////////////////////////////////////////////////////////////////
701 /// \brief Look-ahead assertion.
703 /// before(expr) succeeds if the expr sub-expression would match at the current
704 /// position in the sequence, but expr is not included in the match. For instance,
705 /// before("foo") succeeds if we are before a "foo". Look-ahead assertions can be
706 /// negated with the bit-compliment operator.
708 /// \attention before(expr) is equivalent to the perl (?=...) extension.
709 /// ~before(expr) is a negative look-ahead assertion, equivalent to the
710 /// perl (?!...) extension.
712 /// \param expr The sub-expression to put in the look-ahead assertion.
713 template<typename Expr
>
714 typename
proto::result_of::make_expr
<
715 detail::lookahead_tag
716 , proto::default_domain
719 before(Expr
const &expr
)
721 return proto::make_expr
<
722 detail::lookahead_tag
723 , proto::default_domain
727 ///////////////////////////////////////////////////////////////////////////////
728 /// \brief Look-behind assertion.
730 /// after(expr) succeeds if the expr sub-expression would match at the current
731 /// position minus N in the sequence, where N is the width of expr. expr is not included in
732 /// the match. For instance, after("foo") succeeds if we are after a "foo". Look-behind
733 /// assertions can be negated with the bit-complement operator.
735 /// \attention after(expr) is equivalent to the perl (?<=...) extension.
736 /// ~after(expr) is a negative look-behind assertion, equivalent to the
737 /// perl (?<!...) extension.
739 /// \param expr The sub-expression to put in the look-ahead assertion.
741 /// \pre expr cannot match a variable number of characters.
742 template<typename Expr
>
743 typename
proto::result_of::make_expr
<
744 detail::lookbehind_tag
745 , proto::default_domain
748 after(Expr
const &expr
)
750 return proto::make_expr
<
751 detail::lookbehind_tag
752 , proto::default_domain
756 ///////////////////////////////////////////////////////////////////////////////
757 /// \brief Specify a regex traits or a std::locale.
759 /// imbue() instructs the regex engine to use the specified traits or locale
760 /// when matching the regex. The entire expression must use the same traits/locale.
761 /// For instance, the following specifies a locale for use with a regex:
763 /// sregex rx = imbue(loc)(+digit);
765 /// \param loc The std::locale or regex traits object.
766 template<typename Locale
>
767 inline detail::modifier_op
<detail::locale_modifier
<Locale
> > const
768 imbue(Locale
const &loc
)
770 detail::modifier_op
<detail::locale_modifier
<Locale
> > mod
=
772 detail::locale_modifier
<Locale
>(loc
)
773 , regex_constants::ECMAScript
778 proto::terminal
<detail::attribute_placeholder
<mpl::int_
<1> > >::type
const a1
= {{}};
779 proto::terminal
<detail::attribute_placeholder
<mpl::int_
<2> > >::type
const a2
= {{}};
780 proto::terminal
<detail::attribute_placeholder
<mpl::int_
<3> > >::type
const a3
= {{}};
781 proto::terminal
<detail::attribute_placeholder
<mpl::int_
<4> > >::type
const a4
= {{}};
782 proto::terminal
<detail::attribute_placeholder
<mpl::int_
<5> > >::type
const a5
= {{}};
783 proto::terminal
<detail::attribute_placeholder
<mpl::int_
<6> > >::type
const a6
= {{}};
784 proto::terminal
<detail::attribute_placeholder
<mpl::int_
<7> > >::type
const a7
= {{}};
785 proto::terminal
<detail::attribute_placeholder
<mpl::int_
<8> > >::type
const a8
= {{}};
786 proto::terminal
<detail::attribute_placeholder
<mpl::int_
<9> > >::type
const a9
= {{}};
788 ///////////////////////////////////////////////////////////////////////////////
789 /// \brief Specify which characters to skip when matching a regex.
791 /// <tt>skip()</tt> instructs the regex engine to skip certain characters when matching
792 /// a regex. It is most useful for writing regexes that ignore whitespace.
793 /// For instance, the following specifies a regex that skips whitespace and
797 /// // A sentence is one or more words separated by whitespace
798 /// // and punctuation.
799 /// sregex word = +alpha;
800 /// sregex sentence = skip(set[_s | punct])( +word );
803 /// The way it works in the above example is to insert
804 /// <tt>keep(*set[_s | punct])</tt> before each primitive within the regex.
805 /// A "primitive" includes terminals like strings, character sets and nested
806 /// regexes. A final <tt>*set[_s | punct]</tt> is added to the end of the
807 /// regex. The regex <tt>sentence</tt> specified above is equivalent to
811 /// sregex sentence = +( keep(*set[_s | punct]) >> word )
812 /// >> *set[_s | punct];
815 /// \attention Skipping does not affect how nested regexes are handled because
816 /// they are treated atomically. String literals are also treated
817 /// atomically; that is, no skipping is done within a string literal. So
818 /// <tt>skip(_s)("this that")</tt> is not the same as
819 /// <tt>skip(_s)("this" >> as_xpr("that"))</tt>. The first will only match
820 /// when there is only one space between "this" and "that". The second will
821 /// skip any and all whitespace between "this" and "that".
823 /// \param skip A regex that specifies which characters to skip.
824 template<typename Skip
>
825 detail::skip_directive
<Skip
> skip(Skip
const &skip
)
827 return detail::skip_directive
<Skip
>(skip
);
832 inline void ignore_unused_regex_primitives()
834 ignore_unused(repeat_max
);
836 ignore_unused(epsilon
);
838 ignore_unused(alnum
);
873 ignore_unused(as_xpr
);
877 }} // namespace boost::xpressive