/usr/include/boost/xpressive/regex_primitives.hpp is in libboost1.46-dev 1.46.1-7ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 | ///////////////////////////////////////////////////////////////////////////////
/// \file regex_primitives.hpp
/// Contains the syntax elements for writing static regular expressions.
//
// Copyright 2008 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_XPRESSIVE_REGEX_PRIMITIVES_HPP_EAN_10_04_2005
#define BOOST_XPRESSIVE_REGEX_PRIMITIVES_HPP_EAN_10_04_2005
#include <vector>
#include <climits>
#include <boost/config.hpp>
#include <boost/assert.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/and.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/xpressive/detail/detail_fwd.hpp>
#include <boost/xpressive/detail/core/matchers.hpp>
#include <boost/xpressive/detail/core/regex_domain.hpp>
#include <boost/xpressive/detail/utility/ignore_unused.hpp>
// Doxygen can't handle proto :-(
#ifndef BOOST_XPRESSIVE_DOXYGEN_INVOKED
# include <boost/proto/core.hpp>
# include <boost/proto/transform/arg.hpp>
# include <boost/proto/transform/when.hpp>
# include <boost/xpressive/detail/core/icase.hpp>
# include <boost/xpressive/detail/static/compile.hpp>
# include <boost/xpressive/detail/static/modifier.hpp>
#endif
namespace boost { namespace xpressive { namespace detail
{
typedef assert_word_placeholder<word_boundary<mpl::true_> > assert_word_boundary;
typedef assert_word_placeholder<word_begin> assert_word_begin;
typedef assert_word_placeholder<word_end> assert_word_end;
// workaround msvc-7.1 bug with function pointer types
// within function types:
#if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
#define mark_number(x) proto::call<mark_number(x)>
#define minus_one() proto::make<minus_one()>
#endif
struct push_back : proto::callable
{
typedef int result_type;
template<typename Subs>
int operator ()(Subs &subs, int i) const
{
subs.push_back(i);
return i;
}
};
struct mark_number : proto::callable
{
typedef int result_type;
template<typename Expr>
int operator ()(Expr const &expr) const
{
return expr.mark_number_;
}
};
typedef mpl::int_<-1> minus_one;
// s1 or -s1
struct SubMatch
: proto::or_<
proto::when<basic_mark_tag, push_back(proto::_data, mark_number(proto::_value)) >
, proto::when<proto::negate<basic_mark_tag>, push_back(proto::_data, minus_one()) >
>
{};
struct SubMatchList
: proto::or_<SubMatch, proto::comma<SubMatchList, SubMatch> >
{};
template<typename Subs>
typename enable_if<
mpl::and_<proto::is_expr<Subs>, proto::matches<Subs, SubMatchList> >
, std::vector<int>
>::type
to_vector(Subs const &subs)
{
std::vector<int> subs_;
SubMatchList()(subs, 0, subs_);
return subs_;
}
#if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
#undef mark_number
#undef minus_one
#endif
// replace "Expr" with "keep(*State) >> Expr"
struct skip_primitives : proto::transform<skip_primitives>
{
template<typename Expr, typename State, typename Data>
struct impl : proto::transform_impl<Expr, State, Data>
{
typedef
typename proto::shift_right<
typename proto::unary_expr<
keeper_tag
, typename proto::dereference<State>::type
>::type
, Expr
>::type
result_type;
result_type operator ()(
typename impl::expr_param expr
, typename impl::state_param state
, typename impl::data_param
) const
{
result_type that = {{{state}}, expr};
return that;
}
};
};
struct Primitives
: proto::or_<
proto::terminal<proto::_>
, proto::comma<proto::_, proto::_>
, proto::subscript<proto::terminal<set_initializer>, proto::_>
, proto::assign<proto::terminal<set_initializer>, proto::_>
, proto::assign<proto::terminal<attribute_placeholder<proto::_> >, proto::_>
, proto::complement<Primitives>
>
{};
struct SkipGrammar
: proto::or_<
proto::when<Primitives, skip_primitives>
, proto::assign<proto::terminal<mark_placeholder>, SkipGrammar> // don't "skip" mark tags
, proto::subscript<SkipGrammar, proto::_> // don't put skips in actions
, proto::binary_expr<modifier_tag, proto::_, SkipGrammar> // don't skip modifiers
, proto::unary_expr<lookbehind_tag, proto::_> // don't skip lookbehinds
, proto::nary_expr<proto::_, proto::vararg<SkipGrammar> > // everything else is fair game!
>
{};
template<typename Skip>
struct skip_directive
{
typedef typename proto::result_of::as_expr<Skip>::type skip_type;
skip_directive(Skip const &skip)
: skip_(proto::as_expr(skip))
{}
template<typename Sig>
struct result;
template<typename This, typename Expr>
struct result<This(Expr)>
{
typedef
SkipGrammar::impl<
typename proto::result_of::as_expr<Expr>::type
, skip_type const &
, mpl::void_ &
>
skip_transform;
typedef
typename proto::shift_right<
typename skip_transform::result_type
, typename proto::dereference<skip_type>::type
>::type
type;
};
template<typename Expr>
typename result<skip_directive(Expr)>::type
operator ()(Expr const &expr) const
{
mpl::void_ ignore;
typedef result<skip_directive(Expr)> result_fun;
typename result_fun::type that = {
typename result_fun::skip_transform()(proto::as_expr(expr), this->skip_, ignore)
, {skip_}
};
return that;
}
private:
skip_type skip_;
};
/*
///////////////////////////////////////////////////////////////////////////////
/// INTERNAL ONLY
// BOOST_XPRESSIVE_GLOBAL
// for defining globals that neither violate the One Definition Rule nor
// lead to undefined behavior due to global object initialization order.
//#define BOOST_XPRESSIVE_GLOBAL(type, name, init) \
// namespace detail \
// { \
// template<int Dummy> \
// struct BOOST_PP_CAT(global_pod_, name) \
// { \
// static type const value; \
// private: \
// union type_must_be_pod \
// { \
// type t; \
// char ch; \
// } u; \
// }; \
// template<int Dummy> \
// type const BOOST_PP_CAT(global_pod_, name)<Dummy>::value = init; \
// } \
// type const &name = detail::BOOST_PP_CAT(global_pod_, name)<0>::value
*/
} // namespace detail
/// INTERNAL ONLY (for backwards compatibility)
unsigned int const repeat_max = UINT_MAX-1;
///////////////////////////////////////////////////////////////////////////////
/// \brief For infinite repetition of a sub-expression.
///
/// Magic value used with the repeat\<\>() function template
/// to specify an unbounded repeat. Use as: repeat<17, inf>('a').
/// The equivalent in perl is /a{17,}/.
unsigned int const inf = UINT_MAX-1;
/// INTERNAL ONLY (for backwards compatibility)
proto::terminal<detail::epsilon_matcher>::type const epsilon = {{}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Successfully matches nothing.
///
/// Successfully matches a zero-width sequence. nil always succeeds and
/// never consumes any characters.
proto::terminal<detail::epsilon_matcher>::type const nil = {{}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Matches an alpha-numeric character.
///
/// The regex traits are used to determine which characters are alpha-numeric.
/// To match any character that is not alpha-numeric, use ~alnum.
///
/// \attention alnum is equivalent to /[[:alnum:]]/ in perl. ~alnum is equivalent
/// to /[[:^alnum:]]/ in perl.
proto::terminal<detail::posix_charset_placeholder>::type const alnum = {{"alnum", false}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Matches an alphabetic character.
///
/// The regex traits are used to determine which characters are alphabetic.
/// To match any character that is not alphabetic, use ~alpha.
///
/// \attention alpha is equivalent to /[[:alpha:]]/ in perl. ~alpha is equivalent
/// to /[[:^alpha:]]/ in perl.
proto::terminal<detail::posix_charset_placeholder>::type const alpha = {{"alpha", false}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Matches a blank (horizonal white-space) character.
///
/// The regex traits are used to determine which characters are blank characters.
/// To match any character that is not blank, use ~blank.
///
/// \attention blank is equivalent to /[[:blank:]]/ in perl. ~blank is equivalent
/// to /[[:^blank:]]/ in perl.
proto::terminal<detail::posix_charset_placeholder>::type const blank = {{"blank", false}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Matches a control character.
///
/// The regex traits are used to determine which characters are control characters.
/// To match any character that is not a control character, use ~cntrl.
///
/// \attention cntrl is equivalent to /[[:cntrl:]]/ in perl. ~cntrl is equivalent
/// to /[[:^cntrl:]]/ in perl.
proto::terminal<detail::posix_charset_placeholder>::type const cntrl = {{"cntrl", false}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Matches a digit character.
///
/// The regex traits are used to determine which characters are digits.
/// To match any character that is not a digit, use ~digit.
///
/// \attention digit is equivalent to /[[:digit:]]/ in perl. ~digit is equivalent
/// to /[[:^digit:]]/ in perl.
proto::terminal<detail::posix_charset_placeholder>::type const digit = {{"digit", false}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Matches a graph character.
///
/// The regex traits are used to determine which characters are graphable.
/// To match any character that is not graphable, use ~graph.
///
/// \attention graph is equivalent to /[[:graph:]]/ in perl. ~graph is equivalent
/// to /[[:^graph:]]/ in perl.
proto::terminal<detail::posix_charset_placeholder>::type const graph = {{"graph", false}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Matches a lower-case character.
///
/// The regex traits are used to determine which characters are lower-case.
/// To match any character that is not a lower-case character, use ~lower.
///
/// \attention lower is equivalent to /[[:lower:]]/ in perl. ~lower is equivalent
/// to /[[:^lower:]]/ in perl.
proto::terminal<detail::posix_charset_placeholder>::type const lower = {{"lower", false}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Matches a printable character.
///
/// The regex traits are used to determine which characters are printable.
/// To match any character that is not printable, use ~print.
///
/// \attention print is equivalent to /[[:print:]]/ in perl. ~print is equivalent
/// to /[[:^print:]]/ in perl.
proto::terminal<detail::posix_charset_placeholder>::type const print = {{"print", false}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Matches a punctuation character.
///
/// The regex traits are used to determine which characters are punctuation.
/// To match any character that is not punctuation, use ~punct.
///
/// \attention punct is equivalent to /[[:punct:]]/ in perl. ~punct is equivalent
/// to /[[:^punct:]]/ in perl.
proto::terminal<detail::posix_charset_placeholder>::type const punct = {{"punct", false}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Matches a space character.
///
/// The regex traits are used to determine which characters are space characters.
/// To match any character that is not white-space, use ~space.
///
/// \attention space is equivalent to /[[:space:]]/ in perl. ~space is equivalent
/// to /[[:^space:]]/ in perl.
proto::terminal<detail::posix_charset_placeholder>::type const space = {{"space", false}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Matches an upper-case character.
///
/// The regex traits are used to determine which characters are upper-case.
/// To match any character that is not upper-case, use ~upper.
///
/// \attention upper is equivalent to /[[:upper:]]/ in perl. ~upper is equivalent
/// to /[[:^upper:]]/ in perl.
proto::terminal<detail::posix_charset_placeholder>::type const upper = {{"upper", false}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Matches a hexadecimal digit character.
///
/// The regex traits are used to determine which characters are hex digits.
/// To match any character that is not a hex digit, use ~xdigit.
///
/// \attention xdigit is equivalent to /[[:xdigit:]]/ in perl. ~xdigit is equivalent
/// to /[[:^xdigit:]]/ in perl.
proto::terminal<detail::posix_charset_placeholder>::type const xdigit = {{"xdigit", false}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Beginning of sequence assertion.
///
/// For the character sequence [begin, end), 'bos' matches the
/// zero-width sub-sequence [begin, begin).
proto::terminal<detail::assert_bos_matcher>::type const bos = {{}};
///////////////////////////////////////////////////////////////////////////////
/// \brief End of sequence assertion.
///
/// For the character sequence [begin, end),
/// 'eos' matches the zero-width sub-sequence [end, end).
///
/// \attention Unlike the perl end of sequence assertion \$, 'eos' will
/// not match at the position [end-1, end-1) if *(end-1) is '\\n'. To
/// get that behavior, use (!_n >> eos).
proto::terminal<detail::assert_eos_matcher>::type const eos = {{}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Beginning of line assertion.
///
/// 'bol' matches the zero-width sub-sequence
/// immediately following a logical newline sequence. The regex traits
/// is used to determine what constitutes a logical newline sequence.
proto::terminal<detail::assert_bol_placeholder>::type const bol = {{}};
///////////////////////////////////////////////////////////////////////////////
/// \brief End of line assertion.
///
/// 'eol' matches the zero-width sub-sequence
/// immediately preceeding a logical newline sequence. The regex traits
/// is used to determine what constitutes a logical newline sequence.
proto::terminal<detail::assert_eol_placeholder>::type const eol = {{}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Beginning of word assertion.
///
/// 'bow' matches the zero-width sub-sequence
/// immediately following a non-word character and preceeding a word character.
/// The regex traits are used to determine what constitutes a word character.
proto::terminal<detail::assert_word_begin>::type const bow = {{}};
///////////////////////////////////////////////////////////////////////////////
/// \brief End of word assertion.
///
/// 'eow' matches the zero-width sub-sequence
/// immediately following a word character and preceeding a non-word character.
/// The regex traits are used to determine what constitutes a word character.
proto::terminal<detail::assert_word_end>::type const eow = {{}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Word boundary assertion.
///
/// '_b' matches the zero-width sub-sequence at the beginning or the end of a word.
/// It is equivalent to (bow | eow). The regex traits are used to determine what
/// constitutes a word character. To match a non-word boundary, use ~_b.
///
/// \attention _b is like \\b in perl. ~_b is like \\B in perl.
proto::terminal<detail::assert_word_boundary>::type const _b = {{}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Matches a word character.
///
/// '_w' matches a single word character. The regex traits are used to determine which
/// characters are word characters. Use ~_w to match a character that is not a word
/// character.
///
/// \attention _w is like \\w in perl. ~_w is like \\W in perl.
proto::terminal<detail::posix_charset_placeholder>::type const _w = {{"w", false}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Matches a digit character.
///
/// '_d' matches a single digit character. The regex traits are used to determine which
/// characters are digits. Use ~_d to match a character that is not a digit
/// character.
///
/// \attention _d is like \\d in perl. ~_d is like \\D in perl.
proto::terminal<detail::posix_charset_placeholder>::type const _d = {{"d", false}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Matches a space character.
///
/// '_s' matches a single space character. The regex traits are used to determine which
/// characters are space characters. Use ~_s to match a character that is not a space
/// character.
///
/// \attention _s is like \\s in perl. ~_s is like \\S in perl.
proto::terminal<detail::posix_charset_placeholder>::type const _s = {{"s", false}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Matches a literal newline character, '\\n'.
///
/// '_n' matches a single newline character, '\\n'. Use ~_n to match a character
/// that is not a newline.
///
/// \attention ~_n is like '.' in perl without the /s modifier.
proto::terminal<char>::type const _n = {'\n'};
///////////////////////////////////////////////////////////////////////////////
/// \brief Matches a logical newline sequence.
///
/// '_ln' matches a logical newline sequence. This can be any character in the
/// line separator class, as determined by the regex traits, or the '\\r\\n' sequence.
/// For the purpose of back-tracking, '\\r\\n' is treated as a unit.
/// To match any one character that is not a logical newline, use ~_ln.
detail::logical_newline_xpression const _ln = {{}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Matches any one character.
///
/// Match any character, similar to '.' in perl syntax with the /s modifier.
/// '_' matches any one character, including the newline.
///
/// \attention To match any character except the newline, use ~_n
proto::terminal<detail::any_matcher>::type const _ = {{}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Reference to the current regex object
///
/// Useful when constructing recursive regular expression objects. The 'self'
/// identifier is a short-hand for the current regex object. For instance,
/// sregex rx = '(' >> (self | nil) >> ')'; will create a regex object that
/// matches balanced parens such as "((()))".
proto::terminal<detail::self_placeholder>::type const self = {{}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Used to create character sets.
///
/// There are two ways to create character sets with the 'set' identifier. The
/// easiest is to create a comma-separated list of the characters in the set,
/// as in (set= 'a','b','c'). This set will match 'a', 'b', or 'c'. The other
/// way is to define the set as an argument to the set subscript operator.
/// For instance, set[ 'a' | range('b','c') | digit ] will match an 'a', 'b',
/// 'c' or a digit character.
///
/// To complement a set, apply the '~' operator. For instance, ~(set= 'a','b','c')
/// will match any character that is not an 'a', 'b', or 'c'.
///
/// Sets can be composed of other, possibly complemented, sets. For instance,
/// set[ ~digit | ~(set= 'a','b','c') ].
detail::set_initializer_type const set = {{}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Sub-match placeholder type, used to create named captures in
/// static regexes.
///
/// \c mark_tag is the type of the global sub-match placeholders \c s0, \c s1, etc.. You
/// can use the \c mark_tag type to create your own sub-match placeholders with
/// more meaningful names. This is roughly equivalent to the "named capture"
/// feature of dynamic regular expressions.
///
/// To create a named sub-match placeholder, initialize it with a unique integer.
/// The integer must only be unique within the regex in which the placeholder
/// is used. Then you can use it within static regexes to created sub-matches
/// by assigning a sub-expression to it, or to refer back to already created
/// sub-matches.
///
/// \code
/// mark_tag number(1); // "number" is now equivalent to "s1"
/// // Match a number, followed by a space and the same number again
/// sregex rx = (number = +_d) >> ' ' >> number;
/// \endcode
///
/// After a successful \c regex_match() or \c regex_search(), the sub-match placeholder
/// can be used to index into the <tt>match_results\<\></tt> object to retrieve the
/// corresponding sub-match.
struct mark_tag
: proto::extends<detail::basic_mark_tag, mark_tag, detail::regex_domain>
{
private:
typedef proto::extends<detail::basic_mark_tag, mark_tag, detail::regex_domain> base_type;
static detail::basic_mark_tag make_tag(int mark_nbr)
{
detail::basic_mark_tag mark = {{mark_nbr}};
return mark;
}
public:
/// \brief Initialize a mark_tag placeholder
/// \param mark_nbr An integer that uniquely identifies this \c mark_tag
/// within the static regexes in which this \c mark_tag will be used.
/// \pre <tt>mark_nbr \> 0</tt>
mark_tag(int mark_nbr)
: base_type(mark_tag::make_tag(mark_nbr))
{
// Marks numbers must be integers greater than 0.
BOOST_ASSERT(mark_nbr > 0);
}
/// INTERNAL ONLY
operator detail::basic_mark_tag const &() const
{
return this->proto_base();
}
BOOST_PROTO_EXTENDS_USING_ASSIGN_NON_DEPENDENT(mark_tag)
};
// This macro is used when declaring mark_tags that are global because
// it guarantees that they are statically initialized. That avoids
// order-of-initialization bugs. In user code, the simpler: mark_tag s0(0);
// would be preferable.
/// INTERNAL ONLY
#define BOOST_XPRESSIVE_GLOBAL_MARK_TAG(NAME, VALUE) \
boost::xpressive::mark_tag::proto_base_expr const NAME = {{VALUE}} \
/**/
///////////////////////////////////////////////////////////////////////////////
/// \brief Sub-match placeholder, like $& in Perl
BOOST_XPRESSIVE_GLOBAL_MARK_TAG(s0, 0);
///////////////////////////////////////////////////////////////////////////////
/// \brief Sub-match placeholder, like $1 in perl.
///
/// To create a sub-match, assign a sub-expression to the sub-match placeholder.
/// For instance, (s1= _) will match any one character and remember which
/// character was matched in the 1st sub-match. Later in the pattern, you can
/// refer back to the sub-match. For instance, (s1= _) >> s1 will match any
/// character, and then match the same character again.
///
/// After a successful regex_match() or regex_search(), the sub-match placeholders
/// can be used to index into the match_results\<\> object to retrieve the Nth
/// sub-match.
BOOST_XPRESSIVE_GLOBAL_MARK_TAG(s1, 1);
BOOST_XPRESSIVE_GLOBAL_MARK_TAG(s2, 2);
BOOST_XPRESSIVE_GLOBAL_MARK_TAG(s3, 3);
BOOST_XPRESSIVE_GLOBAL_MARK_TAG(s4, 4);
BOOST_XPRESSIVE_GLOBAL_MARK_TAG(s5, 5);
BOOST_XPRESSIVE_GLOBAL_MARK_TAG(s6, 6);
BOOST_XPRESSIVE_GLOBAL_MARK_TAG(s7, 7);
BOOST_XPRESSIVE_GLOBAL_MARK_TAG(s8, 8);
BOOST_XPRESSIVE_GLOBAL_MARK_TAG(s9, 9);
// NOTE: For the purpose of xpressive's documentation, make icase() look like an
// ordinary function. In reality, it is a function object defined in detail/icase.hpp
// so that it can serve double-duty as regex_constants::icase, the syntax_option_type.
#ifdef BOOST_XPRESSIVE_DOXYGEN_INVOKED
///////////////////////////////////////////////////////////////////////////////
/// \brief Makes a sub-expression case-insensitive.
///
/// Use icase() to make a sub-expression case-insensitive. For instance,
/// "foo" >> icase(set['b'] >> "ar") will match "foo" exactly followed by
/// "bar" irrespective of case.
template<typename Expr> detail::unspecified icase(Expr const &expr) { return 0; }
#endif
///////////////////////////////////////////////////////////////////////////////
/// \brief Makes a literal into a regular expression.
///
/// Use as_xpr() to turn a literal into a regular expression. For instance,
/// "foo" >> "bar" will not compile because both operands to the right-shift
/// operator are const char*, and no such operator exists. Use as_xpr("foo") >> "bar"
/// instead.
///
/// You can use as_xpr() with character literals in addition to string literals.
/// For instance, as_xpr('a') will match an 'a'. You can also complement a
/// character literal, as with ~as_xpr('a'). This will match any one character
/// that is not an 'a'.
#ifdef BOOST_XPRESSIVE_DOXYGEN_INVOKED
template<typename Literal> detail::unspecified as_xpr(Literal const &literal) { return 0; }
#else
proto::functional::as_expr<> const as_xpr = {};
#endif
///////////////////////////////////////////////////////////////////////////////
/// \brief Embed a regex object by reference.
///
/// \param rex The basic_regex object to embed by reference.
template<typename BidiIter>
inline typename proto::terminal<reference_wrapper<basic_regex<BidiIter> const> >::type const
by_ref(basic_regex<BidiIter> const &rex)
{
reference_wrapper<basic_regex<BidiIter> const> ref(rex);
return proto::terminal<reference_wrapper<basic_regex<BidiIter> const> >::type::make(ref);
}
///////////////////////////////////////////////////////////////////////////////
/// \brief Match a range of characters.
///
/// Match any character in the range [ch_min, ch_max].
///
/// \param ch_min The lower end of the range to match.
/// \param ch_max The upper end of the range to match.
template<typename Char>
inline typename proto::terminal<detail::range_placeholder<Char> >::type const
range(Char ch_min, Char ch_max)
{
detail::range_placeholder<Char> that = {ch_min, ch_max, false};
return proto::terminal<detail::range_placeholder<Char> >::type::make(that);
}
///////////////////////////////////////////////////////////////////////////////
/// \brief Make a sub-expression optional. Equivalent to !as_xpr(expr).
///
/// \param expr The sub-expression to make optional.
template<typename Expr>
typename proto::result_of::make_expr<
proto::tag::logical_not
, proto::default_domain
, Expr const &
>::type const
optional(Expr const &expr)
{
return proto::make_expr<
proto::tag::logical_not
, proto::default_domain
>(boost::ref(expr));
}
///////////////////////////////////////////////////////////////////////////////
/// \brief Repeat a sub-expression multiple times.
///
/// There are two forms of the repeat\<\>() function template. To match a
/// sub-expression N times, use repeat\<N\>(expr). To match a sub-expression
/// from M to N times, use repeat\<M,N\>(expr).
///
/// The repeat\<\>() function creates a greedy quantifier. To make the quantifier
/// non-greedy, apply the unary minus operator, as in -repeat\<M,N\>(expr).
///
/// \param expr The sub-expression to repeat.
template<unsigned int Min, unsigned int Max, typename Expr>
typename proto::result_of::make_expr<
detail::generic_quant_tag<Min, Max>
, proto::default_domain
, Expr const &
>::type const
repeat(Expr const &expr)
{
return proto::make_expr<
detail::generic_quant_tag<Min, Max>
, proto::default_domain
>(boost::ref(expr));
}
/// \overload
///
template<unsigned int Count, typename Expr2>
typename proto::result_of::make_expr<
detail::generic_quant_tag<Count, Count>
, proto::default_domain
, Expr2 const &
>::type const
repeat(Expr2 const &expr2)
{
return proto::make_expr<
detail::generic_quant_tag<Count, Count>
, proto::default_domain
>(boost::ref(expr2));
}
///////////////////////////////////////////////////////////////////////////////
/// \brief Create an independent sub-expression.
///
/// Turn off back-tracking for a sub-expression. Any branches or repeats within
/// the sub-expression will match only one way, and no other alternatives are
/// tried.
///
/// \attention keep(expr) is equivalent to the perl (?>...) extension.
///
/// \param expr The sub-expression to modify.
template<typename Expr>
typename proto::result_of::make_expr<
detail::keeper_tag
, proto::default_domain
, Expr const &
>::type const
keep(Expr const &expr)
{
return proto::make_expr<
detail::keeper_tag
, proto::default_domain
>(boost::ref(expr));
}
///////////////////////////////////////////////////////////////////////////////
/// \brief Look-ahead assertion.
///
/// before(expr) succeeds if the expr sub-expression would match at the current
/// position in the sequence, but expr is not included in the match. For instance,
/// before("foo") succeeds if we are before a "foo". Look-ahead assertions can be
/// negated with the bit-compliment operator.
///
/// \attention before(expr) is equivalent to the perl (?=...) extension.
/// ~before(expr) is a negative look-ahead assertion, equivalent to the
/// perl (?!...) extension.
///
/// \param expr The sub-expression to put in the look-ahead assertion.
template<typename Expr>
typename proto::result_of::make_expr<
detail::lookahead_tag
, proto::default_domain
, Expr const &
>::type const
before(Expr const &expr)
{
return proto::make_expr<
detail::lookahead_tag
, proto::default_domain
>(boost::ref(expr));
}
///////////////////////////////////////////////////////////////////////////////
/// \brief Look-behind assertion.
///
/// after(expr) succeeds if the expr sub-expression would match at the current
/// position minus N in the sequence, where N is the width of expr. expr is not included in
/// the match. For instance, after("foo") succeeds if we are after a "foo". Look-behind
/// assertions can be negated with the bit-complement operator.
///
/// \attention after(expr) is equivalent to the perl (?<=...) extension.
/// ~after(expr) is a negative look-behind assertion, equivalent to the
/// perl (?<!...) extension.
///
/// \param expr The sub-expression to put in the look-ahead assertion.
///
/// \pre expr cannot match a variable number of characters.
template<typename Expr>
typename proto::result_of::make_expr<
detail::lookbehind_tag
, proto::default_domain
, Expr const &
>::type const
after(Expr const &expr)
{
return proto::make_expr<
detail::lookbehind_tag
, proto::default_domain
>(boost::ref(expr));
}
///////////////////////////////////////////////////////////////////////////////
/// \brief Specify a regex traits or a std::locale.
///
/// imbue() instructs the regex engine to use the specified traits or locale
/// when matching the regex. The entire expression must use the same traits/locale.
/// For instance, the following specifies a locale for use with a regex:
/// std::locale loc;
/// sregex rx = imbue(loc)(+digit);
///
/// \param loc The std::locale or regex traits object.
template<typename Locale>
inline detail::modifier_op<detail::locale_modifier<Locale> > const
imbue(Locale const &loc)
{
detail::modifier_op<detail::locale_modifier<Locale> > mod =
{
detail::locale_modifier<Locale>(loc)
, regex_constants::ECMAScript
};
return mod;
}
proto::terminal<detail::attribute_placeholder<mpl::int_<1> > >::type const a1 = {{}};
proto::terminal<detail::attribute_placeholder<mpl::int_<2> > >::type const a2 = {{}};
proto::terminal<detail::attribute_placeholder<mpl::int_<3> > >::type const a3 = {{}};
proto::terminal<detail::attribute_placeholder<mpl::int_<4> > >::type const a4 = {{}};
proto::terminal<detail::attribute_placeholder<mpl::int_<5> > >::type const a5 = {{}};
proto::terminal<detail::attribute_placeholder<mpl::int_<6> > >::type const a6 = {{}};
proto::terminal<detail::attribute_placeholder<mpl::int_<7> > >::type const a7 = {{}};
proto::terminal<detail::attribute_placeholder<mpl::int_<8> > >::type const a8 = {{}};
proto::terminal<detail::attribute_placeholder<mpl::int_<9> > >::type const a9 = {{}};
///////////////////////////////////////////////////////////////////////////////
/// \brief Specify which characters to skip when matching a regex.
///
/// <tt>skip()</tt> instructs the regex engine to skip certain characters when matching
/// a regex. It is most useful for writing regexes that ignore whitespace.
/// For instance, the following specifies a regex that skips whitespace and
/// punctuation:
///
/// \code
/// // A sentence is one or more words separated by whitespace
/// // and punctuation.
/// sregex word = +alpha;
/// sregex sentence = skip(set[_s | punct])( +word );
/// \endcode
///
/// The way it works in the above example is to insert
/// <tt>keep(*set[_s | punct])</tt> before each primitive within the regex.
/// A "primitive" includes terminals like strings, character sets and nested
/// regexes. A final <tt>*set[_s | punct]</tt> is added to the end of the
/// regex. The regex <tt>sentence</tt> specified above is equivalent to
/// the following:
///
/// \code
/// sregex sentence = +( keep(*set[_s | punct]) >> word )
/// >> *set[_s | punct];
/// \endcode
///
/// \attention Skipping does not affect how nested regexes are handled because
/// they are treated atomically. String literals are also treated
/// atomically; that is, no skipping is done within a string literal. So
/// <tt>skip(_s)("this that")</tt> is not the same as
/// <tt>skip(_s)("this" >> as_xpr("that"))</tt>. The first will only match
/// when there is only one space between "this" and "that". The second will
/// skip any and all whitespace between "this" and "that".
///
/// \param skip A regex that specifies which characters to skip.
template<typename Skip>
detail::skip_directive<Skip> skip(Skip const &skip)
{
return detail::skip_directive<Skip>(skip);
}
namespace detail
{
inline void ignore_unused_regex_primitives()
{
detail::ignore_unused(repeat_max);
detail::ignore_unused(inf);
detail::ignore_unused(epsilon);
detail::ignore_unused(nil);
detail::ignore_unused(alnum);
detail::ignore_unused(bos);
detail::ignore_unused(eos);
detail::ignore_unused(bol);
detail::ignore_unused(eol);
detail::ignore_unused(bow);
detail::ignore_unused(eow);
detail::ignore_unused(_b);
detail::ignore_unused(_w);
detail::ignore_unused(_d);
detail::ignore_unused(_s);
detail::ignore_unused(_n);
detail::ignore_unused(_ln);
detail::ignore_unused(_);
detail::ignore_unused(self);
detail::ignore_unused(set);
detail::ignore_unused(s0);
detail::ignore_unused(s1);
detail::ignore_unused(s2);
detail::ignore_unused(s3);
detail::ignore_unused(s4);
detail::ignore_unused(s5);
detail::ignore_unused(s6);
detail::ignore_unused(s7);
detail::ignore_unused(s8);
detail::ignore_unused(s9);
detail::ignore_unused(a1);
detail::ignore_unused(a2);
detail::ignore_unused(a3);
detail::ignore_unused(a4);
detail::ignore_unused(a5);
detail::ignore_unused(a6);
detail::ignore_unused(a7);
detail::ignore_unused(a8);
detail::ignore_unused(a9);
detail::ignore_unused(as_xpr);
}
}
}} // namespace boost::xpressive
#endif
|