├── .gitattributes ├── .travis.yml ├── CMakeLists.txt ├── build.jam ├── doc ├── Jamfile.v2 ├── acknowledgements.qbk ├── actions.qbk ├── concepts.qbk ├── dynamic_regexes.qbk ├── examples.qbk ├── grammars.qbk ├── history.qbk ├── installation.qbk ├── introduction.qbk ├── matching.qbk ├── named_captures.qbk ├── nyi.qbk ├── perf.qbk ├── preface.qbk ├── quick_start.qbk ├── regexpp_diffs.qbk ├── results.qbk ├── static_regexes.qbk ├── substitutions.qbk ├── symbols.qbk ├── tips_n_tricks.qbk ├── tokenization.qbk ├── tracking_ptr.qbk ├── traits.qbk └── xpressive.qbk ├── example ├── Jamfile.v2 ├── example.vcproj ├── main.cpp └── numbers.cpp ├── include └── boost │ └── xpressive │ ├── basic_regex.hpp │ ├── detail │ ├── core │ │ ├── access.hpp │ │ ├── action.hpp │ │ ├── adaptor.hpp │ │ ├── finder.hpp │ │ ├── flow_control.hpp │ │ ├── icase.hpp │ │ ├── linker.hpp │ │ ├── list.hpp │ │ ├── matcher │ │ │ ├── action_matcher.hpp │ │ │ ├── alternate_end_matcher.hpp │ │ │ ├── alternate_matcher.hpp │ │ │ ├── any_matcher.hpp │ │ │ ├── assert_bol_matcher.hpp │ │ │ ├── assert_bos_matcher.hpp │ │ │ ├── assert_eol_matcher.hpp │ │ │ ├── assert_eos_matcher.hpp │ │ │ ├── assert_line_base.hpp │ │ │ ├── assert_word_matcher.hpp │ │ │ ├── attr_begin_matcher.hpp │ │ │ ├── attr_end_matcher.hpp │ │ │ ├── attr_matcher.hpp │ │ │ ├── charset_matcher.hpp │ │ │ ├── end_matcher.hpp │ │ │ ├── epsilon_matcher.hpp │ │ │ ├── keeper_matcher.hpp │ │ │ ├── literal_matcher.hpp │ │ │ ├── logical_newline_matcher.hpp │ │ │ ├── lookahead_matcher.hpp │ │ │ ├── lookbehind_matcher.hpp │ │ │ ├── mark_begin_matcher.hpp │ │ │ ├── mark_end_matcher.hpp │ │ │ ├── mark_matcher.hpp │ │ │ ├── optional_matcher.hpp │ │ │ ├── posix_charset_matcher.hpp │ │ │ ├── predicate_matcher.hpp │ │ │ ├── range_matcher.hpp │ │ │ ├── regex_byref_matcher.hpp │ │ │ ├── regex_matcher.hpp │ │ │ ├── repeat_begin_matcher.hpp │ │ │ ├── repeat_end_matcher.hpp │ │ │ ├── set_matcher.hpp │ │ │ ├── simple_repeat_matcher.hpp │ │ │ ├── string_matcher.hpp │ │ │ └── true_matcher.hpp │ │ ├── matchers.hpp │ │ ├── optimize.hpp │ │ ├── peeker.hpp │ │ ├── quant_style.hpp │ │ ├── regex_domain.hpp │ │ ├── regex_impl.hpp │ │ ├── results_cache.hpp │ │ ├── state.hpp │ │ ├── sub_match_impl.hpp │ │ └── sub_match_vector.hpp │ ├── detail_fwd.hpp │ ├── dynamic │ │ ├── dynamic.hpp │ │ ├── matchable.hpp │ │ ├── parse_charset.hpp │ │ ├── parser.hpp │ │ ├── parser_enum.hpp │ │ ├── parser_traits.hpp │ │ └── sequence.hpp │ ├── static │ │ ├── compile.hpp │ │ ├── grammar.hpp │ │ ├── is_pure.hpp │ │ ├── modifier.hpp │ │ ├── placeholders.hpp │ │ ├── static.hpp │ │ ├── transforms │ │ │ ├── as_action.hpp │ │ │ ├── as_alternate.hpp │ │ │ ├── as_independent.hpp │ │ │ ├── as_inverse.hpp │ │ │ ├── as_marker.hpp │ │ │ ├── as_matcher.hpp │ │ │ ├── as_modifier.hpp │ │ │ ├── as_quantifier.hpp │ │ │ ├── as_sequence.hpp │ │ │ └── as_set.hpp │ │ ├── transmogrify.hpp │ │ ├── type_traits.hpp │ │ ├── visitor.hpp │ │ └── width_of.hpp │ └── utility │ │ ├── algorithm.hpp │ │ ├── any.hpp │ │ ├── boyer_moore.hpp │ │ ├── chset │ │ ├── basic_chset.hpp │ │ ├── basic_chset.ipp │ │ ├── chset.hpp │ │ ├── range_run.hpp │ │ └── range_run.ipp │ │ ├── cons.hpp │ │ ├── counted_base.hpp │ │ ├── dont_care.hpp │ │ ├── hash_peek_bitset.hpp │ │ ├── ignore_unused.hpp │ │ ├── literals.hpp │ │ ├── never_true.hpp │ │ ├── save_restore.hpp │ │ ├── sequence_stack.hpp │ │ ├── symbols.hpp │ │ ├── tracking_ptr.hpp │ │ ├── traits_utils.hpp │ │ └── width.hpp │ ├── match_results.hpp │ ├── regex_actions.hpp │ ├── regex_algorithms.hpp │ ├── regex_compiler.hpp │ ├── regex_constants.hpp │ ├── regex_error.hpp │ ├── regex_iterator.hpp │ ├── regex_primitives.hpp │ ├── regex_token_iterator.hpp │ ├── regex_traits.hpp │ ├── sub_match.hpp │ ├── traits │ ├── c_regex_traits.hpp │ ├── cpp_regex_traits.hpp │ ├── detail │ │ └── c_ctype.hpp │ └── null_regex_traits.hpp │ ├── xpressive.hpp │ ├── xpressive_dynamic.hpp │ ├── xpressive_fwd.hpp │ ├── xpressive_static.hpp │ └── xpressive_typeof.hpp ├── index.html ├── meta └── libraries.json ├── perf ├── Jamfile.v2 ├── command_line.cpp ├── gcc │ ├── long_twain_search.xml │ ├── short_matches.xml │ └── short_twain_search.xml ├── main.cpp ├── msvc │ ├── long_twain_search.xml │ ├── short_matches.xml │ └── short_twain_search.xml ├── regex_comparison.hpp ├── time_boost.cpp ├── time_dynamic_xpressive.cpp └── time_static_xpressive.cpp ├── test ├── Jamfile.v2 ├── c_traits.cpp ├── c_traits_u.cpp ├── misc1.cpp ├── misc2.cpp ├── multiple_defs1.cpp ├── multiple_defs2.cpp ├── regress.cpp ├── regress.ipp ├── regress.txt ├── regress_u.cpp ├── test.hpp ├── test1.cpp ├── test1.hpp ├── test10.cpp ├── test10.hpp ├── test10u.cpp ├── test11.cpp ├── test11.hpp ├── test11u.cpp ├── test1u.cpp ├── test2.cpp ├── test2.hpp ├── test2u.cpp ├── test3.cpp ├── test3.hpp ├── test3u.cpp ├── test4.cpp ├── test4.hpp ├── test4u.cpp ├── test5.cpp ├── test5.hpp ├── test5u.cpp ├── test6.cpp ├── test6.hpp ├── test6u.cpp ├── test7.cpp ├── test7.hpp ├── test7u.cpp ├── test8.cpp ├── test8.hpp ├── test8u.cpp ├── test9.cpp ├── test9.hpp ├── test9u.cpp ├── test_actions.cpp ├── test_assert.cpp ├── test_assert_with_placeholder.cpp ├── test_basic_regex.cpp ├── test_cycles.cpp ├── test_dynamic.cpp ├── test_dynamic_grammar.cpp ├── test_format.cpp ├── test_match_results.cpp ├── test_non_char.cpp ├── test_partial_match.cpp ├── test_regex_algorithms.cpp ├── test_regex_compiler.cpp ├── test_regex_constants.cpp ├── test_regex_error.cpp ├── test_regex_iterator.cpp ├── test_regex_primitives.cpp ├── test_regex_token_iterator.cpp ├── test_regex_traits.cpp ├── test_skip.cpp ├── test_static.cpp ├── test_sub_match.cpp ├── test_symbols.cpp ├── test_typeof.cpp └── test_typeof2.cpp └── tools ├── Jamfile.v2 └── perl2xpr.cpp /.travis.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2016, 2017 Peter Dimov 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) 4 | 5 | language: cpp 6 | 7 | sudo: false 8 | 9 | python: "2.7" 10 | 11 | branches: 12 | only: 13 | - master 14 | - develop 15 | - /feature\/.*/ 16 | 17 | env: 18 | matrix: 19 | - BOGUS_JOB=true 20 | 21 | matrix: 22 | 23 | exclude: 24 | - env: BOGUS_JOB=true 25 | 26 | include: 27 | - os: linux 28 | compiler: g++ 29 | env: TOOLSET=gcc CXXSTD=03,11 30 | 31 | - os: linux 32 | compiler: clang++ 33 | env: TOOLSET=clang CXXSTD=03,11,14,1z 34 | addons: 35 | apt: 36 | packages: 37 | - libstdc++-4.9-dev 38 | sources: 39 | - ubuntu-toolchain-r-test 40 | 41 | - os: osx 42 | compiler: clang++ 43 | env: TOOLSET=clang CXXSTD=03,11,14,1z 44 | 45 | install: 46 | - BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true 47 | - cd .. 48 | - git clone -b $BOOST_BRANCH https://github.com/boostorg/boost.git boost-root 49 | - cd boost-root 50 | - git submodule update --init tools/build 51 | - git submodule update --init libs/config 52 | - git submodule update --init tools/boostdep 53 | - cp -r $TRAVIS_BUILD_DIR/* libs/xpressive 54 | - python tools/boostdep/depinst/depinst.py xpressive 55 | - ./bootstrap.sh 56 | - ./b2 headers 57 | 58 | script: 59 | - ./b2 libs/xpressive/test toolset=$TOOLSET cxxstd=$CXXSTD 60 | 61 | notifications: 62 | email: 63 | on_success: always 64 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated by `boostdep --cmake xpressive` 2 | # Copyright 2020 Peter Dimov 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # https://www.boost.org/LICENSE_1_0.txt 5 | 6 | cmake_minimum_required(VERSION 3.5...3.16) 7 | 8 | project(boost_xpressive VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) 9 | 10 | add_library(boost_xpressive INTERFACE) 11 | add_library(Boost::xpressive ALIAS boost_xpressive) 12 | 13 | target_include_directories(boost_xpressive INTERFACE include) 14 | 15 | target_link_libraries(boost_xpressive 16 | INTERFACE 17 | Boost::assert 18 | Boost::config 19 | Boost::conversion 20 | Boost::core 21 | Boost::exception 22 | Boost::fusion 23 | Boost::integer 24 | Boost::iterator 25 | Boost::lexical_cast 26 | Boost::mpl 27 | Boost::numeric_conversion 28 | Boost::optional 29 | Boost::preprocessor 30 | Boost::proto 31 | Boost::range 32 | Boost::smart_ptr 33 | Boost::static_assert 34 | Boost::throw_exception 35 | Boost::type_traits 36 | Boost::typeof 37 | Boost::utility 38 | ) 39 | 40 | if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") 41 | 42 | add_subdirectory(test) 43 | 44 | endif() 45 | 46 | -------------------------------------------------------------------------------- /build.jam: -------------------------------------------------------------------------------- 1 | # Copyright René Ferdinand Rivera Morell 2023-2024 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | require-b2 5.2 ; 7 | 8 | constant boost_dependencies : 9 | /boost/assert//boost_assert 10 | /boost/config//boost_config 11 | /boost/conversion//boost_conversion 12 | /boost/core//boost_core 13 | /boost/exception//boost_exception 14 | /boost/fusion//boost_fusion 15 | /boost/integer//boost_integer 16 | /boost/iterator//boost_iterator 17 | /boost/lexical_cast//boost_lexical_cast 18 | /boost/mpl//boost_mpl 19 | /boost/numeric_conversion//boost_numeric_conversion 20 | /boost/optional//boost_optional 21 | /boost/preprocessor//boost_preprocessor 22 | /boost/proto//boost_proto 23 | /boost/range//boost_range 24 | /boost/smart_ptr//boost_smart_ptr 25 | /boost/static_assert//boost_static_assert 26 | /boost/throw_exception//boost_throw_exception 27 | /boost/type_traits//boost_type_traits 28 | /boost/typeof//boost_typeof 29 | /boost/utility//boost_utility ; 30 | 31 | project /boost/xpressive 32 | ; 33 | 34 | explicit 35 | [ alias boost_xpressive : : : 36 | : include $(boost_dependencies) ] 37 | [ alias all : boost_xpressive example perf test tools ] 38 | ; 39 | 40 | call-if : boost-library xpressive 41 | ; 42 | 43 | -------------------------------------------------------------------------------- /doc/Jamfile.v2: -------------------------------------------------------------------------------- 1 | # Copyright Eric Niebler 2005. Use, modification, and distribution are 2 | # subject to the Boost Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | 5 | import doxygen ; 6 | import quickbook ; 7 | 8 | doxygen autodoc 9 | : 10 | [ glob ../include/boost/xpressive/*.hpp ] 11 | [ glob ../include/boost/xpressive/traits/*.hpp ] 12 | : 13 | EXTRACT_ALL=YES 14 | "PREDEFINED=\"BOOST_XPRESSIVE_DOXYGEN_INVOKED\" \\ 15 | \"BOOST_DEDUCED_TYPENAME=typename\" \\ 16 | \"BOOST_XPRESSIVE_GLOBAL_MARK_TAG(x,y)=mark_tag const x(y)\" \\ 17 | \"BOOST_STATIC_CONSTANT(x,y)=static x const y\" \\ 18 | \"BOOST_XPR_NONDEDUCED_TYPE_(X)=X\" \\ 19 | \"BOOST_PROTO_DISABLE_IF_IS_CONST(X)=\" \\ 20 | \"UNREF(X)=typename remove_reference::type\" \\ 21 | \"UNCV(X)=typename remove_const::type\" \\ 22 | \"UNREF(X)=typename remove_reference::type\" \\ 23 | \"UNCVREF(X)=typename remove_const::type>::type\"" 24 | HIDE_UNDOC_MEMBERS=NO 25 | EXTRACT_PRIVATE=NO 26 | ENABLE_PREPROCESSING=YES 27 | MACRO_EXPANSION=YES 28 | EXPAND_ONLY_PREDEF=YES 29 | SEARCH_INCLUDES=YES 30 | INCLUDE_PATH=$(BOOST_ROOT) 31 | # So that Doxygen comments can link to sections in the quickbook users' guide 32 | "ALIASES=\"RefSect{2}=\\xmlonly\\2\\endxmlonly\"" 33 | ; 34 | 35 | xml xpressive 36 | : 37 | xpressive.qbk 38 | ; 39 | 40 | boostbook standalone 41 | : 42 | xpressive 43 | : 44 | boost.root=../../../.. 45 | toc.max.depth=3 46 | toc.section.depth=3 47 | chunk.section.depth=3 48 | autodoc 49 | pdf:boost.url.prefix=http://www.boost.org/doc/libs/release/doc/html 50 | ; 51 | 52 | ############################################################################### 53 | alias boostdoc 54 | : xpressive 55 | : 56 | : autodoc 57 | : ; 58 | explicit boostdoc ; 59 | alias boostrelease ; 60 | explicit boostrelease ; 61 | -------------------------------------------------------------------------------- /doc/acknowledgements.qbk: -------------------------------------------------------------------------------- 1 | [/ 2 | / Copyright (c) 2008 Eric Niebler 3 | / 4 | / Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | /] 7 | 8 | [section Acknowledgments] 9 | 10 | I am indebted to [@http://boost.org/people/joel_de_guzman.htm Joel de Guzman] 11 | and [@http://boost.org/people/hartmut_kaiser.htm Hartmut Kaiser] for their 12 | expert advice during the early states of xpressive's development. Much of 13 | static xpressive's syntax is owes a large debt to _spirit_, including the 14 | syntax for xpressive's semantic actions. I am thankful for 15 | [@http://boost.org/people/john_maddock.htm John Maddock]'s excellent work on 16 | his proposal to add regular expressions to the standard library, and for 17 | various ideas borrowed liberally from his regex implementation. I'd also like 18 | to thank [@http://moderncppdesign.com/ Andrei Alexandrescu] for his input 19 | regarding the behavior of nested regex objects, and 20 | [@http://boost.org/people/dave_abrahams.htm Dave Abrahams] for his suggestions 21 | regarding the regex domain-specific embedded language. Noel Belcourt helped 22 | porting xpressive to the Metrowerks CodeWarrior compiler. Markus 23 | Sch'''ö'''pflin helped to track down a bug on HP Tru64, and Steven 24 | Watanabe suggested the fix. 25 | 26 | Special thanks are due to David Jenkins who contributed both ideas, code and 27 | documentation for xpressive's semantic actions, symbol tables and attributes. 28 | Xpressive's ternary search trie implementation is David's, as is the number 29 | parser example in [^libs/xpressive/example/numbers.cpp] and the documentation 30 | for symbol tables and attributes. 31 | 32 | Thanks to John Fletcher for helping track down a runtime assertion when using 33 | xpressive with Howard Hinnant's most excellent libc++. 34 | 35 | Finally, I would like to thank [@http://boost.org/people/thomas_witt.html Thomas Witt] 36 | for acting as xpressive's review manager. 37 | 38 | [endsect] 39 | -------------------------------------------------------------------------------- /doc/dynamic_regexes.qbk: -------------------------------------------------------------------------------- 1 | [/ 2 | / Copyright (c) 2008 Eric Niebler 3 | / 4 | / Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | /] 7 | 8 | [section Dynamic Regexes] 9 | 10 | [h2 Overview] 11 | 12 | Static regexes are dandy, but sometimes you need something a bit more ... dynamic. Imagine you are developing 13 | a text editor with a regex search/replace feature. You need to accept a regular expression from the end user 14 | as input at run-time. There should be a way to parse a string into a regular expression. That's what xpressive's 15 | dynamic regexes are for. They are built from the same core components as their static counterparts, but they 16 | are late-bound so you can specify them at run-time. 17 | 18 | [h2 Construction and Assignment] 19 | 20 | There are two ways to create a dynamic regex: with the _regex_compile_ 21 | function or with the _regex_compiler_ class template. Use _regex_compile_ 22 | if you want the default locale. Use _regex_compiler_ if you need to 23 | specify a different locale. In the section on 24 | [link boost_xpressive.user_s_guide.grammars_and_nested_matches regex grammars], 25 | we'll see another use for _regex_compiler_. 26 | 27 | Here is an example of using `basic_regex<>::compile()`: 28 | 29 | sregex re = sregex::compile( "this|that", regex_constants::icase ); 30 | 31 | Here is the same example using _regex_compiler_: 32 | 33 | sregex_compiler compiler; 34 | sregex re = compiler.compile( "this|that", regex_constants::icase ); 35 | 36 | _regex_compile_ is implemented in terms of _regex_compiler_. 37 | 38 | [h2 Dynamic xpressive Syntax] 39 | 40 | Since the dynamic syntax is not constrained by the rules for valid C++ expressions, we are free to use familiar 41 | syntax for dynamic regexes. For this reason, the syntax used by xpressive for dynamic regexes follows the 42 | lead set by John Maddock's [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1429.htm proposal] 43 | to add regular expressions to the Standard Library. It is essentially the syntax standardized by 44 | [@http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf ECMAScript], with minor changes 45 | in support of internationalization. 46 | 47 | Since the syntax is documented exhaustively elsewhere, I will simply refer you to the existing standards, rather 48 | than duplicate the specification here. 49 | 50 | [h2 Internationalization] 51 | 52 | As with static regexes, dynamic regexes support internationalization by allowing you to specify a different 53 | `std::locale`. To do this, you must use _regex_compiler_. The _regex_compiler_ class has an `imbue()` function. 54 | After you have imbued a _regex_compiler_ object with a custom `std::locale`, all regex objects compiled by 55 | that _regex_compiler_ will use that locale. For example: 56 | 57 | std::locale my_locale = /* initialize your locale object here */; 58 | sregex_compiler compiler; 59 | compiler.imbue( my_locale ); 60 | sregex re = compiler.compile( "\\w+|\\d+" ); 61 | 62 | This regex will use `my_locale` when evaluating the intrinsic character sets `"\\w"` and `"\\d"`. 63 | 64 | [endsect] 65 | -------------------------------------------------------------------------------- /doc/history.qbk: -------------------------------------------------------------------------------- 1 | [/ 2 | / Copyright (c) 2008 Eric Niebler 3 | / 4 | / Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | /] 7 | 8 | [section Appendix 1: History] 9 | 10 | [h2 Version 2.1.0 6/12/2008] 11 | 12 | New Features: 13 | 14 | * `skip()` primitive for static regexes, which allows you to specify parts of 15 | the input string to ignore during regex matching. 16 | * Range-based `regex_replace()` algorithm interface. 17 | * `regex_replace()` accepts formatter objects and formatter lambda expressions 18 | in addition to format strings. 19 | 20 | Bugs Fixed: 21 | 22 | * Semantic actions in look-aheads, look-behinds and independent sub-expressions 23 | execute eagerly instead of causing a crash. 24 | 25 | [h2 Version 2.0.1 10/23/2007] 26 | 27 | Bugs Fixed: 28 | 29 | * `sub_match<>` constructor copies singular iterator causing debug assert. 30 | 31 | [h2 Version 2.0.0, 10/12/2007] 32 | 33 | New Features: 34 | 35 | * Semantic actions 36 | * Custom assertions 37 | * Named captures 38 | * Dynamic regex grammars 39 | * Recursive dynamic regexes with [^(?R)] construct 40 | * Support for searching non-character data 41 | * Better errors for invalid static regexes 42 | * Range-based regex algorithm interface 43 | * `match_flag_type::format_perl`, `match_flag_type::format_sed`, and `match_flag_type::format_all` 44 | * `operator+(std::string, sub_match<>)` and variants 45 | * Version 2 regex traits get `tolower()` and `toupper()` 46 | 47 | Bugs Fixed: 48 | 49 | * Complementing single-character sets like `~(set='a')` works. 50 | 51 | [h2 Version 1.0.2, April 27, 2007] 52 | 53 | Bugs Fixed: 54 | 55 | * Back-references greater than nine work as advertized. 56 | 57 | This is the version that shipped as part of Boost 1.34. 58 | 59 | [h2 Version 1.0.1, October 2, 2006] 60 | 61 | Bugs Fixed: 62 | 63 | * `match_results::position()` works for nested results. 64 | 65 | [h2 Version 1.0.0, March 16, 2006] 66 | 67 | Version 1.0! 68 | 69 | [h2 Version 0.9.6, August 19, 2005] 70 | 71 | The version reviewed for acceptance into Boost. The review began September 8, 72 | 2005. Xpressive was accepted into Boost on September 28, 2005. 73 | 74 | [h2 Version 0.9.3, June 30, 2005] 75 | 76 | New Features: 77 | 78 | * TR1-style regex_traits interface 79 | * Speed enhancements 80 | * `syntax_option_type::ignore_white_space` 81 | 82 | [h2 Version 0.9.0, September 2, 2004] 83 | 84 | New Features: 85 | 86 | * It sort of works. 87 | 88 | [h2 Version 0.0.1, November 16, 2003] 89 | 90 | Announcement of xpressive: 91 | [@http://lists.boost.org/Archives/boost/2003/11/56312.php] 92 | 93 | [endsect] 94 | -------------------------------------------------------------------------------- /doc/installation.qbk: -------------------------------------------------------------------------------- 1 | [/ 2 | / Copyright (c) 2008 Eric Niebler 3 | / 4 | / Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | /] 7 | 8 | [section Installing xpressive] 9 | 10 | [h2 Getting xpressive] 11 | 12 | There are two ways to get xpressive. The first and simplest is to download 13 | the latest version of Boost. Just go to [@http://sf.net/projects/boost] and 14 | follow the ["Download] link. 15 | 16 | The second way is by directly accessing the Boost Subversion repository. 17 | Just go to [@http://svn.boost.org/trac/boost/] and follow the instructions there for 18 | anonymous Subversion access. The version in Boost Subversion is unstable. 19 | 20 | [h2 Building with xpressive] 21 | 22 | Xpressive is a header-only template library, which means you don't need to alter 23 | your build scripts or link to any separate lib file to use it. All you need to 24 | do is `#include `. If you are only using static 25 | regexes, you can improve compile times by only including `xpressive_static.hpp`. 26 | Likewise, you can include `xpressive_dynamic.hpp` if you only plan on using 27 | dynamic regexes. 28 | 29 | If you would also like to use semantic actions or custom assertions with your 30 | static regexes, you will need to additionally include `regex_actions.hpp`. 31 | 32 | [h2 Requirements] 33 | 34 | Xpressive requires Boost version 1.34.1 or higher. 35 | 36 | [h2 Supported Compilers] 37 | 38 | Currently, Boost.Xpressive is known to work on the following compilers: 39 | 40 | * Visual C++ 7.1 and higher 41 | * GNU C++ 3.4 and higher 42 | * Intel for Linux 8.1 and higher 43 | * Intel for Windows 10 and higher 44 | * tru64cxx 71 and higher 45 | * MinGW 3.4 and higher 46 | * HP C/aC++ A.06.14 47 | 48 | [/ * QNX qcc 3.3 and higher] 49 | [/ * Metrowerks CodeWarrior 9.4 and higher] 50 | 51 | Check the latest tests results at Boost's 52 | [@http://beta.boost.org/development/tests/trunk/developer/xpressive.html 53 | Regression Results Page]. 54 | 55 | [note Please send any questions, comments and bug reports to eric 56 | boost-consulting com.] 57 | 58 | [endsect] 59 | -------------------------------------------------------------------------------- /doc/nyi.qbk: -------------------------------------------------------------------------------- 1 | [/ 2 | / Copyright (c) 2008 Eric Niebler 3 | / 4 | / Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | /] 7 | 8 | [section Appendix 2: Not Yet Implemented] 9 | 10 | The following features are planned for xpressive 2.X: 11 | 12 | * `syntax_option_type::collate` 13 | * Collation sequences such as [^'''[.a.]'''] 14 | * Equivalence classes like [^'''[=a=]'''] 15 | * Control of nested results generation with `syntax_option_type::nosubs`, 16 | and a `nosubs()` modifier for static xpressive. 17 | 18 | Here are some wish-list features. You or your company should 19 | consider hiring me to implement them! 20 | 21 | * Optimized DFA back-end for simple, fast regexing. 22 | * Different regex compiler front ends for basic, extended, awk, grep 23 | and egrep regex syntax. 24 | * Fine-grained control over the dynamic regex syntax 25 | * Optional integration with ICU for full Unicode support. 26 | * Improved localization support, possibly as a custom facet for `std::locale`. 27 | 28 | [endsect] 29 | -------------------------------------------------------------------------------- /doc/preface.qbk: -------------------------------------------------------------------------------- 1 | [/ 2 | / Copyright (c) 2008 Eric Niebler 3 | / 4 | / Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | /] 7 | 8 | [section Preface] 9 | 10 | [:['Wife:] New Shimmer is a floor wax!\n 11 | ['Husband:] No, new Shimmer is a dessert topping!\n 12 | ['Wife:] It's a floor wax!\n 13 | ['Husband:] It's a dessert topping!\n 14 | ['Wife:] It's a floor wax, I'm telling you!\n 15 | ['Husband:] It's a dessert topping, you cow!\n 16 | ['Announcer:] Hey, hey, hey, calm down, you two. New Shimmer is both a floor wax ['and] a dessert topping!] 17 | [:[*['-- Saturday Night Live]]] 18 | 19 | [h2 Description] 20 | 21 | xpressive is an advanced, object-oriented regular expression template library for C++. 22 | Regular expressions can be written as strings that are parsed at run-time, or as expression 23 | templates that are parsed at compile-time. Regular expressions can refer to each other and 24 | to themselves recursively, allowing you to build arbitrarily complicated grammars out of 25 | them. 26 | 27 | [h2 Motivation] 28 | 29 | If you need to manipulate text in C++, you have typically had two disjoint options: a regular 30 | expression engine or a parser generator. Regular expression engines (like _regexpp_) are powerful 31 | and flexible; patterns are represented as strings which can be specified at runtime. However, 32 | that means that syntax errors are likewise not detected until runtime. Also, regular expressions 33 | are ill-suited to advanced text processing tasks such as matching balanced, nested tags. Those 34 | tasks have traditionally been handled by parser generators (like the _spirit_fx_). These 35 | beasts are more powerful but less flexible. They generally don't allow you to arbitrarily modify 36 | your grammar rules on the fly. In addition, they don't have the exhaustive backtracking semantics 37 | of regular expressions, which can make it more challenging to author some types of patterns. 38 | 39 | xpressive brings these two approaches seamlessly together and occupies a unique niche in the 40 | world of C++ text processing. With xpressive, you can choose to use it much as you would use 41 | _regexpp_, representing regular expressions as strings. Or you can use it as you would use _spirit_, 42 | writing your regexes as C++ expressions, enjoying all the benefits of an embedded language 43 | dedicated to text manipulation. What's more, you can mix the two to get the benefits of 44 | both, writing regular expression ['grammars] in which some of the regular expressions are 45 | statically bound -- hard-coded and syntax\-checked by the compiler \-- and others are dynamically 46 | bound and specified at runtime. These regular expressions can refer to each other recursively, 47 | matching patterns in strings that ordinary regular expressions cannot. 48 | 49 | [h2 Influences and Related Work] 50 | 51 | The design of xpressive's interface has been strongly influenced by John Maddock's 52 | _regexpp_ library and his _proposal_ 53 | to add regular expressions to the Standard Library. I also drew a great deal of 54 | inspiration from Joel de Guzman's _spirit_fx_, which served as the model 55 | for static xpressive. Other sources of inspiration are the _perl6_ redesign and _greta_. 56 | (You can read a summary of the changes Perl 6 will bring to regex culture 57 | [@http://dev.perl.org/perl6/doc/design/syn/S05.html here].) 58 | 59 | [endsect] 60 | -------------------------------------------------------------------------------- /doc/regexpp_diffs.qbk: -------------------------------------------------------------------------------- 1 | [/ 2 | / Copyright (c) 2008 Eric Niebler 3 | / 4 | / Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | /] 7 | 8 | [section Appendix 3: Differences from Boost.Regex] 9 | 10 | Since many of xpressive's users are likely to be familiar with the _regexpp_ library, 11 | I would be remiss if I failed to point out some important differences between xpressive 12 | and _regexpp_. In particular:\n 13 | 14 | * `xpressive::basic_regex<>` is a template on the iterator type, not the character type. 15 | * `xpressive::basic_regex<>` cannot be constructed directly from a string; rather, you must use 16 | `basic_regex::compile()` or `regex_compiler<>` to build a regex object from a string. 17 | * `xpressive::basic_regex<>` does not have an `imbue()` member function; rather, the `imbue()` member 18 | function is in the `xpressive::regex_compiler<>` factory. 19 | * `boost::basic_regex<>` has a subset of `std::basic_string<>`'s members. `xpressive::basic_regex<>` 20 | does not. The members lacking are: `assign()`, `operator[]()`, `max_size()`, `begin()`, `end()`, 21 | `size()`, `compare()`, and `operator=(std::basic_string<>)`. 22 | * Other member functions that exist in `boost::basic_regex<>` but do not exist in 23 | `xpressive::basic_regex<>` are: `set_expression()`, `get_allocator()`, `imbue()`, `getloc()`, 24 | `getflags()`, and `str()`. 25 | * `xpressive::basic_regex<>` does not have a RegexTraits template parameter. Customization of regex 26 | syntax and localization behavior will be controlled by `regex_compiler<>` and a custom regex facet 27 | for `std::locale`. 28 | * `xpressive::basic_regex<>` and `xpressive::match_results<>` do not have an Allocator template 29 | parameter. This is by design. 30 | * `match_not_dot_null` and `match_not_dot_newline` have moved from the `match_flag_type` enum to the 31 | `syntax_option_type` enum, and they have changed names to `not_dot_null` and `not_dot_newline`. 32 | * The following `syntax_option_type` enumeration values are not supported: `escape_in_lists`, 33 | `char_classes`, `intervals`, `limited_ops`, `newline_alt`, `bk_plus_qm`, `bk_braces`, `bk_parens`, 34 | `bk_refs`, `bk_vbar`, `use_except`, `failbit`, `literal`, `perlex`, `basic`, `extended`, `emacs`, 35 | `awk`, `grep` ,`egrep`, `sed`, `JavaScript`, `JScript`. 36 | * The following `match_flag_type` enumeration values are not supported: `match_not_bob`, 37 | `match_not_eob`, `match_perl`, `match_posix`, and `match_extra`. 38 | 39 | Also, in the current implementation, the regex algorithms in xpressive will not detect 40 | pathological behavior and abort by throwing an exception. It is up to you to write efficient 41 | patterns that do not behave pathologically. 42 | 43 | [endsect] 44 | -------------------------------------------------------------------------------- /example/Jamfile.v2: -------------------------------------------------------------------------------- 1 | # (C) Copyright 2004: Eric Niebler 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | 5 | project 6 | : requirements 7 | /boost/xpressive//boost_xpressive 8 | msvc-8.0:_SCL_SECURE_NO_DEPRECATE 9 | msvc-9.0:_SCL_SECURE_NO_DEPRECATE 10 | msvc,stlport:_STLP_EXPOSE_GLOBALS_IMPLEMENTATION 11 | /boost/assign//boost_assign 12 | ; 13 | 14 | exe examples 15 | : 16 | main.cpp 17 | ; 18 | 19 | exe numbers 20 | : 21 | numbers.cpp 22 | ; 23 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/action.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // action.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_ACTION_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_ACTION_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include // for type_info_less 18 | 19 | namespace boost { namespace xpressive { namespace detail 20 | { 21 | 22 | /////////////////////////////////////////////////////////////////////////////// 23 | // actionable 24 | // 25 | struct actionable 26 | { 27 | virtual ~actionable() {} 28 | virtual void execute(action_args_type *) const {} 29 | 30 | actionable() 31 | : next(0) 32 | {} 33 | 34 | actionable const *next; 35 | }; 36 | 37 | }}} // namespace boost::xpressive::detail 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/adaptor.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // adaptor.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_ADAPTOR_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_ADAPTOR_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | namespace boost { namespace xpressive { namespace detail 23 | { 24 | 25 | /////////////////////////////////////////////////////////////////////////////// 26 | // xpression_adaptor 27 | // 28 | // wrap a static xpression in a matchable interface so it can be stored 29 | // in and invoked from a basic_regex object. 30 | template 31 | struct xpression_adaptor 32 | : Base // either matchable or matchable_ex 33 | { 34 | typedef typename Base::iterator_type iterator_type; 35 | typedef typename iterator_value::type char_type; 36 | 37 | Xpr xpr_; 38 | 39 | xpression_adaptor(Xpr const &xpr) 40 | #if BOOST_WORKAROUND(__GNUC__, BOOST_TESTED_AT(4)) 41 | // Ugh, gcc has an optimizer bug which elides this c'tor call 42 | // resulting in pure virtual function calls. 43 | __attribute__((__noinline__)) 44 | #endif 45 | : xpr_(xpr) 46 | { 47 | } 48 | 49 | virtual bool match(match_state &state) const 50 | { 51 | typedef typename boost::unwrap_reference::type xpr_type; 52 | return implicit_cast(this->xpr_).match(state); 53 | } 54 | 55 | void link(xpression_linker &linker) const 56 | { 57 | this->xpr_.link(linker); 58 | } 59 | 60 | void peek(xpression_peeker &peeker) const 61 | { 62 | this->xpr_.peek(peeker); 63 | } 64 | 65 | private: 66 | xpression_adaptor &operator =(xpression_adaptor const &); 67 | }; 68 | 69 | /////////////////////////////////////////////////////////////////////////////// 70 | // make_adaptor 71 | // 72 | template 73 | inline intrusive_ptr make_adaptor(Xpr const &xpr) 74 | { 75 | return intrusive_ptr(new xpression_adaptor(xpr)); 76 | } 77 | 78 | }}} // namespace boost::xpressive::detail 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/flow_control.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // flow_control.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_FLOW_CONTROL_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_FLOW_CONTROL_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace boost { namespace xpressive { namespace detail 22 | { 23 | 24 | /////////////////////////////////////////////////////////////////////////////// 25 | // push_context_match 26 | // 27 | template 28 | inline bool push_context_match 29 | ( 30 | regex_impl const &impl 31 | , match_state &state 32 | , matchable const &next 33 | ) 34 | { 35 | // avoid infinite recursion 36 | // BUGBUG this only catches direct infinite recursion, like sregex::compile("(?R)"), but 37 | // not indirect infinite recursion where two rules invoke each other recursively. 38 | if(state.is_active_regex(impl) && state.cur_ == state.sub_match(0).begin_) 39 | { 40 | return next.match(state); 41 | } 42 | 43 | // save state 44 | match_context context = state.push_context(impl, next, context); 45 | detail::ignore_unused(context); 46 | 47 | // match the nested regex and uninitialize the match context 48 | // (reclaims the sub_match objects if necessary) 49 | return state.pop_context(impl, impl.xpr_->match(state)); 50 | } 51 | 52 | /////////////////////////////////////////////////////////////////////////////// 53 | // pop_context_match 54 | // 55 | template 56 | inline bool pop_context_match(match_state &state) 57 | { 58 | // save state 59 | // BUGBUG nested regex could have changed state.traits_ 60 | match_context &context(*state.context_.prev_context_); 61 | state.swap_context(context); 62 | 63 | // Finished matching the nested regex; now match the rest of the enclosing regex 64 | bool success = context.next_ptr_->match(state); 65 | 66 | // restore state 67 | state.swap_context(context); 68 | return success; 69 | } 70 | 71 | }}} // namespace boost::xpressive::detail 72 | 73 | #endif 74 | 75 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/icase.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // icase.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_ICASE_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_ICASE_HPP_EAN_10_04_2005 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost { namespace xpressive { namespace regex_constants 18 | { 19 | 20 | /////////////////////////////////////////////////////////////////////////////// 21 | /// \brief Makes a sub-expression case-insensitive. 22 | /// 23 | /// Use icase() to make a sub-expression case-insensitive. For instance, 24 | /// "foo" >> icase(set['b'] >> "ar") will match "foo" exactly followed by 25 | /// "bar" irrespective of case. 26 | detail::modifier_op const icase = {{}, regex_constants::icase_}; 27 | 28 | } // namespace regex_constants 29 | 30 | using regex_constants::icase; 31 | 32 | namespace detail 33 | { 34 | inline void ignore_unused_icase() 35 | { 36 | detail::ignore_unused(icase); 37 | } 38 | } 39 | 40 | }} // namespace boost::xpressive 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/alternate_end_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // alternate_end_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ALTERNATE_END_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ALTERNATE_END_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | # pragma warning(push) 15 | # pragma warning(disable : 4100) // unreferenced formal parameter 16 | #endif 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | namespace boost { namespace xpressive { namespace detail 23 | { 24 | 25 | /////////////////////////////////////////////////////////////////////////////// 26 | // alternate_end_matcher 27 | // 28 | struct alternate_end_matcher 29 | : quant_style_assertion 30 | { 31 | mutable void const *back_; 32 | 33 | alternate_end_matcher() 34 | : back_(0) 35 | { 36 | } 37 | 38 | template 39 | bool match(match_state &state, Next const &next) const 40 | { 41 | return next.pop_match(state, this->back_); 42 | } 43 | }; 44 | 45 | }}} 46 | 47 | #if defined(_MSC_VER) 48 | # pragma warning(pop) 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/any_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // any_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ANY_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ANY_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { namespace xpressive { namespace detail 21 | { 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // any_matcher 25 | // 26 | struct any_matcher 27 | { 28 | BOOST_XPR_QUANT_STYLE(quant_fixed_width, 1, true) 29 | 30 | template 31 | static bool match(match_state &state, Next const &next) 32 | { 33 | if(state.eos()) 34 | { 35 | return false; 36 | } 37 | 38 | ++state.cur_; 39 | if(next.match(state)) 40 | { 41 | return true; 42 | } 43 | 44 | --state.cur_; 45 | return false; 46 | } 47 | }; 48 | 49 | }}} 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/assert_bol_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // assert_bol_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ASSERT_BOL_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ASSERT_BOL_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | namespace boost { namespace xpressive { namespace detail 23 | { 24 | 25 | /////////////////////////////////////////////////////////////////////////////// 26 | // assert_bol_matcher 27 | // 28 | template 29 | struct assert_bol_matcher 30 | : assert_line_base 31 | { 32 | typedef typename Traits::char_type char_type; 33 | 34 | assert_bol_matcher(Traits const &tr) 35 | : assert_line_base(tr) 36 | { 37 | } 38 | 39 | template 40 | bool match(match_state &state, Next const &next) const 41 | { 42 | if(state.bos()) 43 | { 44 | if(!state.flags_.match_bol_) 45 | { 46 | return false; 47 | } 48 | } 49 | else 50 | { 51 | char_type ch = *boost::prior(state.cur_); 52 | 53 | // If the previous character is not a newline, we're not at the start of a line 54 | if(!traits_cast(state).isctype(ch, this->newline_)) 55 | { 56 | return false; 57 | } 58 | // There is no line-break between \r and \n 59 | else if(ch == this->cr_ && !state.eos() && *state.cur_ == this->nl_) 60 | { 61 | return false; 62 | } 63 | } 64 | 65 | return next.match(state); 66 | } 67 | }; 68 | 69 | }}} 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/assert_bos_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // assert_bos_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ASSERT_BOS_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ASSERT_BOS_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { namespace xpressive { namespace detail 21 | { 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // assert_bos_matcher 25 | // match the beginning of the sequence (\A) 26 | struct assert_bos_matcher 27 | { 28 | BOOST_XPR_QUANT_STYLE(quant_none, 0, true) 29 | 30 | template 31 | static bool match(match_state &state, Next const &next) 32 | { 33 | return state.bos() && next.match(state); 34 | } 35 | }; 36 | 37 | }}} 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/assert_eol_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // assert_eol_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ASSERT_EOL_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ASSERT_EOL_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | namespace boost { namespace xpressive { namespace detail 23 | { 24 | 25 | /////////////////////////////////////////////////////////////////////////////// 26 | // assert_eol_matcher 27 | // 28 | template 29 | struct assert_eol_matcher 30 | : assert_line_base 31 | { 32 | typedef typename Traits::char_type char_type; 33 | 34 | assert_eol_matcher(Traits const &tr) 35 | : assert_line_base(tr) 36 | { 37 | } 38 | 39 | template 40 | bool match(match_state &state, Next const &next) const 41 | { 42 | if(state.eos()) 43 | { 44 | if(!state.flags_.match_eol_) 45 | { 46 | return false; 47 | } 48 | } 49 | else 50 | { 51 | char_type ch = *state.cur_; 52 | 53 | // If the current character is not a newline, we're not at the end of a line 54 | if(!traits_cast(state).isctype(ch, this->newline_)) 55 | { 56 | return false; 57 | } 58 | // There is no line-break between \r and \n 59 | else if(ch == this->nl_ && (!state.bos() || state.flags_.match_prev_avail_) && *boost::prior(state.cur_) == this->cr_) 60 | { 61 | return false; 62 | } 63 | } 64 | 65 | return next.match(state); 66 | } 67 | }; 68 | 69 | }}} 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/assert_eos_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // assert_eos_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ASSERT_EOS_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ASSERT_EOS_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { namespace xpressive { namespace detail 21 | { 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // assert_eos_matcher 25 | // match the end of the sequence (\Z) 26 | struct assert_eos_matcher 27 | { 28 | BOOST_XPR_QUANT_STYLE(quant_none, 0, true) 29 | 30 | template 31 | static bool match(match_state &state, Next const &next) 32 | { 33 | return state.eos() && next.match(state); 34 | } 35 | }; 36 | 37 | }}} 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/assert_line_base.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // assert_line_base.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_DETAIL_ASSERT_LINE_BASE_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_DETAIL_ASSERT_LINE_BASE_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { namespace xpressive { namespace detail 21 | { 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // assert_line_base 25 | // 26 | template 27 | struct assert_line_base 28 | : quant_style_assertion 29 | { 30 | typedef typename Traits::char_type char_type; 31 | typedef typename Traits::char_class_type char_class_type; 32 | 33 | protected: 34 | assert_line_base(Traits const &tr) 35 | : newline_(lookup_classname(tr, "newline")) 36 | , nl_(tr.widen('\n')) 37 | , cr_(tr.widen('\r')) 38 | { 39 | } 40 | 41 | char_class_type newline_; 42 | char_type nl_, cr_; 43 | }; 44 | 45 | }}} 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/attr_begin_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // attr_begin_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ATTR_BEGIN_MATCHER_HPP_EAN_06_09_2007 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ATTR_BEGIN_MATCHER_HPP_EAN_06_09_2007 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { namespace xpressive { namespace detail 21 | { 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // attr_begin_matcher 25 | // 26 | template 27 | struct attr_begin_matcher 28 | : quant_style 29 | { 30 | template 31 | static bool match(match_state &state, Next const &next) 32 | { 33 | void const *attr_slots[Nbr::value] = {}; 34 | attr_context old_attr_context = state.attr_context_; 35 | state.attr_context_.attr_slots_ = attr_slots; 36 | state.attr_context_.prev_attr_context_ = &old_attr_context; 37 | 38 | if(next.match(state)) 39 | { 40 | return true; 41 | } 42 | 43 | state.attr_context_ = old_attr_context; 44 | return false; 45 | } 46 | }; 47 | 48 | }}} 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/attr_end_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // attr_end_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ATTR_END_MATCHER_HPP_EAN_06_09_2007 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ATTR_END_MATCHER_HPP_EAN_06_09_2007 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { namespace xpressive { namespace detail 21 | { 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // attr_end_matcher 25 | // 26 | struct attr_end_matcher 27 | : quant_style 28 | { 29 | template 30 | static bool match(match_state &state, Next const &next) 31 | { 32 | attr_context old_attr_context = state.attr_context_; 33 | state.attr_context_ = *old_attr_context.prev_attr_context_; 34 | 35 | if(next.match(state)) 36 | { 37 | return true; 38 | } 39 | 40 | state.attr_context_ = old_attr_context; 41 | return false; 42 | } 43 | }; 44 | 45 | }}} 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/charset_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // charset_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_CHARSET_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_CHARSET_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { namespace xpressive { namespace detail 21 | { 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // charset_matcher 25 | // 26 | template 27 | struct charset_matcher 28 | : quant_style_fixed_width<1> 29 | { 30 | typedef typename Traits::char_type char_type; 31 | typedef Traits traits_type; 32 | typedef ICase icase_type; 33 | 34 | charset_matcher(CharSet const &charset = CharSet()) 35 | : charset_(charset) 36 | { 37 | } 38 | 39 | void inverse() 40 | { 41 | this->charset_.inverse(); 42 | } 43 | 44 | template 45 | bool match(match_state &state, Next const &next) const 46 | { 47 | if(state.eos() || !this->charset_.test(*state.cur_, traits_cast(state), icase_type())) 48 | { 49 | return false; 50 | } 51 | 52 | ++state.cur_; 53 | if(next.match(state)) 54 | { 55 | return true; 56 | } 57 | 58 | --state.cur_; 59 | return false; 60 | } 61 | 62 | CharSet charset_; 63 | }; 64 | 65 | }}} 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/end_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // end_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_END_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_END_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | namespace boost { namespace xpressive { namespace detail 24 | { 25 | 26 | /////////////////////////////////////////////////////////////////////////////// 27 | // end_matcher 28 | // 29 | struct end_matcher 30 | : quant_style_assertion 31 | { 32 | template 33 | static bool match(match_state &state, Next const &) 34 | { 35 | BidiIter const tmp = state.cur_; 36 | sub_match_impl &s0 = state.sub_match(0); 37 | BOOST_ASSERT(!s0.matched); 38 | 39 | // SPECIAL: if there is a match context on the context stack, then 40 | // this pattern has been nested within another. pop that context and 41 | // continue executing. 42 | if(0 != state.context_.prev_context_) 43 | { 44 | if(!pop_context_match(state)) 45 | { 46 | return false; 47 | } 48 | 49 | // record the end of sub-match zero 50 | s0.first = s0.begin_; 51 | s0.second = tmp; 52 | s0.matched = true; 53 | 54 | return true; 55 | } 56 | else if((state.flags_.match_all_ && !state.eos()) || 57 | (state.flags_.match_not_null_ && state.cur_ == s0.begin_)) 58 | { 59 | return false; 60 | } 61 | 62 | // record the end of sub-match zero 63 | s0.first = s0.begin_; 64 | s0.second = tmp; 65 | s0.matched = true; 66 | 67 | // Now execute any actions that have been queued 68 | for(actionable const *actor = state.action_list_.next; 0 != actor; actor = actor->next) 69 | { 70 | actor->execute(state.action_args_); 71 | } 72 | 73 | return true; 74 | } 75 | }; 76 | 77 | /////////////////////////////////////////////////////////////////////////////// 78 | // independent_end_matcher 79 | // 80 | struct independent_end_matcher 81 | : quant_style_assertion 82 | { 83 | template 84 | bool match(match_state &state, Next const &) const 85 | { 86 | // Now execute any actions that have been queued 87 | for(actionable const *actor = state.action_list_.next; 0 != actor; actor = actor->next) 88 | { 89 | actor->execute(state.action_args_); 90 | } 91 | 92 | return true; 93 | } 94 | }; 95 | 96 | }}} 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/epsilon_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // epsilon_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_EPSILON_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_EPSILON_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { namespace xpressive { namespace detail 21 | { 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // epsilon_matcher 25 | // 26 | struct epsilon_matcher 27 | { 28 | BOOST_XPR_QUANT_STYLE(quant_none, 0, true) 29 | 30 | template 31 | static bool match(match_state &state, Next const &next) 32 | { 33 | return next.match(state); 34 | } 35 | }; 36 | 37 | }}} 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/keeper_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // keeper_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_KEEPER_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_KEEPER_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace boost { namespace xpressive { namespace detail 22 | { 23 | 24 | /////////////////////////////////////////////////////////////////////////////// 25 | // keeper_matcher 26 | // Xpr can be either a static_xpression, or a shared_matchable 27 | template 28 | struct keeper_matcher 29 | : quant_style 30 | { 31 | keeper_matcher(Xpr const &xpr, bool pure = Xpr::pure) 32 | : xpr_(xpr) 33 | , pure_(pure) 34 | { 35 | } 36 | 37 | template 38 | bool match(match_state &state, Next const &next) const 39 | { 40 | return Xpr::pure || this->pure_ 41 | ? this->match_(state, next, mpl::true_()) 42 | : this->match_(state, next, mpl::false_()); 43 | } 44 | 45 | template 46 | bool match_(match_state &state, Next const &next, mpl::true_) const 47 | { 48 | BidiIter const tmp = state.cur_; 49 | 50 | // matching xpr is guaranteed to not produce side-effects, don't bother saving state 51 | if(!this->xpr_.match(state)) 52 | { 53 | return false; 54 | } 55 | else if(next.match(state)) 56 | { 57 | return true; 58 | } 59 | 60 | state.cur_ = tmp; 61 | return false; 62 | } 63 | 64 | template 65 | bool match_(match_state &state, Next const &next, mpl::false_) const 66 | { 67 | BidiIter const tmp = state.cur_; 68 | 69 | // matching xpr could produce side-effects, save state 70 | memento mem = save_sub_matches(state); 71 | 72 | if(!this->xpr_.match(state)) 73 | { 74 | restore_action_queue(mem, state); 75 | reclaim_sub_matches(mem, state, false); 76 | return false; 77 | } 78 | restore_action_queue(mem, state); 79 | if(next.match(state)) 80 | { 81 | reclaim_sub_matches(mem, state, true); 82 | return true; 83 | } 84 | 85 | restore_sub_matches(mem, state); 86 | state.cur_ = tmp; 87 | return false; 88 | } 89 | 90 | Xpr xpr_; 91 | bool pure_; // false if matching xpr_ could modify the sub-matches 92 | }; 93 | 94 | }}} 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/literal_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // literal_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_LITERAL_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_LITERAL_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace boost { namespace xpressive { namespace detail 22 | { 23 | 24 | /////////////////////////////////////////////////////////////////////////////// 25 | // literal_matcher 26 | // 27 | template 28 | struct literal_matcher 29 | : quant_style_fixed_width<1> 30 | { 31 | typedef typename Traits::char_type char_type; 32 | typedef Not not_type; 33 | typedef ICase icase_type; 34 | char_type ch_; 35 | 36 | explicit literal_matcher(char_type ch) 37 | : ch_(ch) 38 | {} 39 | 40 | literal_matcher(char_type ch, Traits const &tr) 41 | : ch_(detail::translate(ch, tr, icase_type())) 42 | {} 43 | 44 | template 45 | bool match(match_state &state, Next const &next) const 46 | { 47 | if(state.eos() || Not::value == 48 | (detail::translate(*state.cur_, traits_cast(state), icase_type()) == this->ch_)) 49 | { 50 | return false; 51 | } 52 | 53 | ++state.cur_; 54 | if(next.match(state)) 55 | { 56 | return true; 57 | } 58 | 59 | --state.cur_; 60 | return false; 61 | } 62 | }; 63 | 64 | }}} 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/logical_newline_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // logical_newline_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_LOGICAL_NEWLINE_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_LOGICAL_NEWLINE_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { namespace xpressive { namespace detail 21 | { 22 | 23 | ////////////////////////////////////////////////////////////////////////// 24 | // logical_newline_matcher 25 | // 26 | template 27 | struct logical_newline_matcher 28 | : quant_style_variable_width 29 | { 30 | typedef typename Traits::char_type char_type; 31 | typedef typename Traits::char_class_type char_class_type; 32 | 33 | logical_newline_matcher(Traits const &tr) 34 | : newline_(lookup_classname(tr, "newline")) 35 | , nl_(tr.widen('\n')) 36 | , cr_(tr.widen('\r')) 37 | { 38 | } 39 | 40 | template 41 | bool match(match_state &state, Next const &next) const 42 | { 43 | if(state.eos()) 44 | { 45 | return false; 46 | } 47 | 48 | char_type ch = *state.cur_; 49 | if(traits_cast(state).isctype(ch, this->newline_)) 50 | { 51 | ++state.cur_; 52 | if(this->cr_ == ch && !state.eos() && this->nl_ == *state.cur_) 53 | { 54 | ++state.cur_; 55 | if(next.match(state)) 56 | { 57 | return true; 58 | } 59 | --state.cur_; 60 | } 61 | else if(next.match(state)) 62 | { 63 | return true; 64 | } 65 | 66 | --state.cur_; 67 | } 68 | return false; 69 | } 70 | 71 | char_class_type newline() const 72 | { 73 | return this->newline_; 74 | } 75 | 76 | private: 77 | char_class_type newline_; 78 | char_type nl_, cr_; 79 | }; 80 | 81 | }}} 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/mark_begin_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // mark_begin_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_MARK_BEGIN_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_MARK_BEGIN_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { namespace xpressive { namespace detail 21 | { 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // mark_begin_matcher 25 | // 26 | struct mark_begin_matcher 27 | : quant_style 28 | { 29 | int mark_number_; // signed because it could be negative 30 | 31 | mark_begin_matcher(int mark_number) 32 | : mark_number_(mark_number) 33 | { 34 | } 35 | 36 | template 37 | bool match(match_state &state, Next const &next) const 38 | { 39 | sub_match_impl &br = state.sub_match(this->mark_number_); 40 | 41 | BidiIter old_begin = br.begin_; 42 | br.begin_ = state.cur_; 43 | 44 | if(next.match(state)) 45 | { 46 | return true; 47 | } 48 | 49 | br.begin_ = old_begin; 50 | return false; 51 | } 52 | }; 53 | 54 | }}} 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/mark_end_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // mark_end_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_MARK_END_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_MARK_END_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { namespace xpressive { namespace detail 21 | { 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // mark_end_matcher 25 | // 26 | struct mark_end_matcher 27 | : quant_style 28 | { 29 | int mark_number_; 30 | 31 | mark_end_matcher(int mark_number) 32 | : mark_number_(mark_number) 33 | { 34 | } 35 | 36 | template 37 | bool match(match_state &state, Next const &next) const 38 | { 39 | sub_match_impl &br = state.sub_match(this->mark_number_); 40 | 41 | BidiIter old_first = br.first; 42 | BidiIter old_second = br.second; 43 | bool old_matched = br.matched; 44 | 45 | br.first = br.begin_; 46 | br.second = state.cur_; 47 | br.matched = true; 48 | 49 | if(next.match(state)) 50 | { 51 | return true; 52 | } 53 | 54 | br.first = old_first; 55 | br.second = old_second; 56 | br.matched = old_matched; 57 | 58 | return false; 59 | } 60 | }; 61 | 62 | }}} 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/mark_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // mark_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_MARK_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_MARK_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | namespace boost { namespace xpressive { namespace detail 23 | { 24 | 25 | // TODO: the mark matcher is acually a fixed-width matcher, but the width is 26 | // not known until pattern match time. 27 | 28 | /////////////////////////////////////////////////////////////////////////////// 29 | // mark_matcher 30 | // 31 | template 32 | struct mark_matcher 33 | : quant_style_variable_width 34 | { 35 | typedef ICase icase_type; 36 | int mark_number_; 37 | 38 | mark_matcher(int mark_number, Traits const &) 39 | : mark_number_(mark_number) 40 | { 41 | } 42 | 43 | template 44 | bool match(match_state &state, Next const &next) const 45 | { 46 | BOOST_ASSERT(this->mark_number_ < static_cast(state.mark_count_)); 47 | sub_match_impl const &br = state.sub_match(this->mark_number_); 48 | 49 | if(!br.matched) 50 | { 51 | return false; 52 | } 53 | 54 | BidiIter const tmp = state.cur_; 55 | for(BidiIter begin = br.first, end = br.second; begin != end; ++begin, ++state.cur_) 56 | { 57 | if(state.eos() 58 | || detail::translate(*state.cur_, traits_cast(state), icase_type()) 59 | != detail::translate(*begin, traits_cast(state), icase_type())) 60 | { 61 | state.cur_ = tmp; 62 | return false; 63 | } 64 | } 65 | 66 | if(next.match(state)) 67 | { 68 | return true; 69 | } 70 | 71 | state.cur_ = tmp; 72 | return false; 73 | } 74 | }; 75 | 76 | }}} 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/posix_charset_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // posix_charset_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_POSIX_CHARSET_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_POSIX_CHARSET_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | namespace boost { namespace xpressive { namespace detail 24 | { 25 | 26 | /////////////////////////////////////////////////////////////////////////////// 27 | // posix_charset_matcher 28 | // 29 | template 30 | struct posix_charset_matcher 31 | : quant_style_fixed_width<1> 32 | { 33 | typedef Traits traits_type; 34 | typedef typename Traits::char_class_type char_class_type; 35 | 36 | posix_charset_matcher(char_class_type m, bool no) 37 | : not_(no) 38 | , mask_(m) 39 | { 40 | BOOST_ASSERT(0 != this->mask_); 41 | } 42 | 43 | void inverse() 44 | { 45 | this->not_ = !this->not_; 46 | } 47 | 48 | template 49 | bool match(match_state &state, Next const &next) const 50 | { 51 | if(state.eos() || this->not_ == traits_cast(state).isctype( 52 | *state.cur_, this->mask_)) 53 | { 54 | return false; 55 | } 56 | 57 | ++state.cur_; 58 | if(next.match(state)) 59 | { 60 | return true; 61 | } 62 | 63 | --state.cur_; 64 | return false; 65 | } 66 | 67 | bool not_; 68 | char_class_type mask_; 69 | }; 70 | 71 | }}} 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/range_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // range_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_RANGE_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_RANGE_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | # pragma warning(push) 15 | # pragma warning(disable : 4100) // unreferenced formal parameter 16 | #endif 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | namespace boost { namespace xpressive { namespace detail 24 | { 25 | 26 | /////////////////////////////////////////////////////////////////////////////// 27 | // range_matcher 28 | // 29 | template 30 | struct range_matcher 31 | : quant_style_fixed_width<1> 32 | { 33 | typedef typename Traits::char_type char_type; 34 | typedef ICase icase_type; 35 | char_type ch_min_; 36 | char_type ch_max_; 37 | bool not_; 38 | 39 | range_matcher(char_type ch_min, char_type ch_max, bool no, Traits const &) 40 | : ch_min_(ch_min) 41 | , ch_max_(ch_max) 42 | , not_(no) 43 | { 44 | } 45 | 46 | void inverse() 47 | { 48 | this->not_ = !this->not_; 49 | } 50 | 51 | bool in_range(Traits const &tr, char_type ch, mpl::false_) const // case-sensitive 52 | { 53 | return tr.in_range(this->ch_min_, this->ch_max_, ch); 54 | } 55 | 56 | bool in_range(Traits const &tr, char_type ch, mpl::true_) const // case-insensitive 57 | { 58 | return tr.in_range_nocase(this->ch_min_, this->ch_max_, ch); 59 | } 60 | 61 | template 62 | bool match(match_state &state, Next const &next) const 63 | { 64 | if(state.eos() || this->not_ == 65 | this->in_range(traits_cast(state), *state.cur_, icase_type())) 66 | { 67 | return false; 68 | } 69 | 70 | ++state.cur_; 71 | if(next.match(state)) 72 | { 73 | return true; 74 | } 75 | 76 | --state.cur_; 77 | return false; 78 | } 79 | }; 80 | 81 | }}} 82 | 83 | #if defined(_MSC_VER) 84 | # pragma warning(pop) 85 | #endif 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/regex_byref_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // regex_byref_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_REGEX_BYREF_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_REGEX_BYREF_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace boost { namespace xpressive { namespace detail 28 | { 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // regex_byref_matcher 31 | // 32 | template 33 | struct regex_byref_matcher 34 | : quant_style 35 | { 36 | // avoid cyclic references by holding a weak_ptr to the 37 | // regex_impl struct 38 | weak_ptr > wimpl_; 39 | 40 | // the basic_regex object holds a ref-count to this regex_impl, so 41 | // we don't have to worry about it going away. 42 | regex_impl const *pimpl_; 43 | 44 | regex_byref_matcher(shared_ptr > const &impl) 45 | : wimpl_(impl) 46 | , pimpl_(impl.get()) 47 | { 48 | BOOST_ASSERT(this->pimpl_); 49 | } 50 | 51 | template 52 | bool match(match_state &state, Next const &next) const 53 | { 54 | BOOST_ASSERT(this->pimpl_ == this->wimpl_.lock().get()); 55 | BOOST_XPR_ENSURE_(this->pimpl_->xpr_, regex_constants::error_badref, "bad regex reference"); 56 | 57 | return push_context_match(*this->pimpl_, state, this->wrap_(next, is_static_xpression())); 58 | } 59 | 60 | private: 61 | template 62 | static xpression_adaptor, matchable > wrap_(Next const &next, mpl::true_) 63 | { 64 | // wrap the static xpression in a matchable interface 65 | return xpression_adaptor, matchable >(boost::cref(next)); 66 | } 67 | 68 | template 69 | static Next const &wrap_(Next const &next, mpl::false_) 70 | { 71 | return next; 72 | } 73 | }; 74 | 75 | }}} 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/regex_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // regex_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_REGEX_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_REGEX_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | namespace boost { namespace xpressive { namespace detail 26 | { 27 | 28 | /////////////////////////////////////////////////////////////////////////////// 29 | // regex_matcher 30 | // 31 | template 32 | struct regex_matcher 33 | : quant_style 34 | { 35 | regex_impl impl_; 36 | 37 | regex_matcher(shared_ptr > const &impl) 38 | : impl_() 39 | { 40 | this->impl_.xpr_ = impl->xpr_; 41 | this->impl_.traits_ = impl->traits_; 42 | this->impl_.mark_count_ = impl->mark_count_; 43 | this->impl_.hidden_mark_count_ = impl->hidden_mark_count_; 44 | 45 | BOOST_XPR_ENSURE_(this->impl_.xpr_, regex_constants::error_badref, "bad regex reference"); 46 | } 47 | 48 | template 49 | bool match(match_state &state, Next const &next) const 50 | { 51 | // regex_matcher is used for embeding a dynamic regex in a static regex. As such, 52 | // Next will always point to a static regex. 53 | BOOST_MPL_ASSERT((is_static_xpression)); 54 | 55 | // wrap the static xpression in a matchable interface 56 | xpression_adaptor, matchable > adaptor(boost::cref(next)); 57 | return push_context_match(this->impl_, state, adaptor); 58 | } 59 | }; 60 | 61 | }}} 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/repeat_begin_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // repeat_end_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_REPEAT_BEGIN_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_REPEAT_BEGIN_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { namespace xpressive { namespace detail 21 | { 22 | 23 | // 24 | // Note: here is the variable-width xpression quantifier. It always 25 | // matches at least once, so if the min is 0, it is the responsibility 26 | // of the parser to make it alternate with an epsilon matcher. 27 | // 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // repeat_begin_matcher 31 | // 32 | struct repeat_begin_matcher 33 | : quant_style 34 | { 35 | int mark_number_; 36 | 37 | repeat_begin_matcher(int mark_number) 38 | : mark_number_(mark_number) 39 | { 40 | } 41 | 42 | template 43 | bool match(match_state &state, Next const &next) const 44 | { 45 | sub_match_impl &br = state.sub_match(this->mark_number_); 46 | 47 | unsigned int old_repeat_count = br.repeat_count_; 48 | bool old_zero_width = br.zero_width_; 49 | 50 | br.repeat_count_ = 1; 51 | br.zero_width_ = false; 52 | 53 | // "push" next onto the stack, so it can be "popped" in 54 | // repeat_end_matcher and used to loop back. 55 | if(next.BOOST_NESTED_TEMPLATE push_match(state)) 56 | { 57 | return true; 58 | } 59 | 60 | br.repeat_count_ = old_repeat_count; 61 | br.zero_width_ = old_zero_width; 62 | 63 | return false; 64 | } 65 | }; 66 | 67 | }}} 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/set_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // set.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_SET_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_SET_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | # pragma warning(push) 15 | # pragma warning(disable : 4127) // conditional expression constant 16 | # pragma warning(disable : 4100) // unreferenced formal parameter 17 | # pragma warning(disable : 4351) // vc8 new behavior: elements of array 'foo' will be default initialized 18 | #endif 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace boost { namespace xpressive { namespace detail 28 | { 29 | 30 | /////////////////////////////////////////////////////////////////////////////// 31 | // set_matcher 32 | // 33 | template 34 | struct set_matcher 35 | : quant_style_fixed_width<1> 36 | { 37 | typedef typename Traits::char_type char_type; 38 | char_type set_[ Size::value ]; 39 | bool not_; 40 | bool icase_; 41 | 42 | set_matcher() 43 | : set_() 44 | , not_(false) 45 | , icase_(false) 46 | { 47 | } 48 | 49 | void inverse() 50 | { 51 | this->not_ = !this->not_; 52 | } 53 | 54 | void nocase(Traits const &tr) 55 | { 56 | this->icase_ = true; 57 | 58 | for(int i = 0; i < Size::value; ++i) 59 | { 60 | this->set_[i] = tr.translate_nocase(this->set_[i]); 61 | } 62 | } 63 | 64 | bool in_set(Traits const &tr, char_type ch) const 65 | { 66 | char_type const *begin = &this->set_[0], *end = begin + Size::value; 67 | ch = this->icase_ ? tr.translate_nocase(ch) : tr.translate(ch); 68 | return end != std::find(begin, end, ch); 69 | } 70 | 71 | template 72 | bool match(match_state &state, Next const &next) const 73 | { 74 | if(state.eos() || this->not_ == this->in_set(traits_cast(state), *state.cur_)) 75 | { 76 | return false; 77 | } 78 | 79 | if(++state.cur_, next.match(state)) 80 | { 81 | return true; 82 | } 83 | 84 | return --state.cur_, false; 85 | } 86 | }; 87 | 88 | /////////////////////////////////////////////////////////////////////////////// 89 | // set_initializer 90 | struct set_initializer 91 | { 92 | }; 93 | 94 | #if defined(_MSC_VER) 95 | # pragma warning(pop) 96 | #endif 97 | 98 | }}} // namespace boost::xpressive::detail 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/string_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // string_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_STRING_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_STRING_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace boost { namespace xpressive { namespace detail 25 | { 26 | /////////////////////////////////////////////////////////////////////////////// 27 | // string_matcher 28 | // 29 | template 30 | struct string_matcher 31 | : quant_style_fixed_unknown_width 32 | { 33 | typedef typename Traits::char_type char_type; 34 | typedef typename Traits::string_type string_type; 35 | typedef ICase icase_type; 36 | string_type str_; 37 | char_type const *end_; 38 | 39 | string_matcher(string_type const &str, Traits const &tr) 40 | : str_(str) 41 | , end_() 42 | { 43 | typename range_iterator::type cur = boost::begin(this->str_); 44 | typename range_iterator::type end = boost::end(this->str_); 45 | for(; cur != end; ++cur) 46 | { 47 | *cur = detail::translate(*cur, tr, icase_type()); 48 | } 49 | this->end_ = detail::data_end(str_); 50 | } 51 | 52 | string_matcher(string_matcher const &that) 53 | : str_(that.str_) 54 | , end_(detail::data_end(str_)) 55 | { 56 | } 57 | 58 | template 59 | bool match(match_state &state, Next const &next) const 60 | { 61 | BidiIter const tmp = state.cur_; 62 | char_type const *begin = detail::data_begin(this->str_); 63 | for(; begin != this->end_; ++begin, ++state.cur_) 64 | { 65 | if(state.eos() || 66 | (detail::translate(*state.cur_, traits_cast(state), icase_type()) != *begin)) 67 | { 68 | state.cur_ = tmp; 69 | return false; 70 | } 71 | } 72 | 73 | if(next.match(state)) 74 | { 75 | return true; 76 | } 77 | 78 | state.cur_ = tmp; 79 | return false; 80 | } 81 | 82 | detail::width get_width() const 83 | { 84 | return boost::size(this->str_); 85 | } 86 | }; 87 | 88 | }}} 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matcher/true_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // true_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_TRUE_MATCHER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_TRUE_MATCHER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { namespace xpressive { namespace detail 21 | { 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // true_matcher 25 | // 26 | struct true_matcher 27 | : quant_style_assertion 28 | { 29 | template 30 | static bool match(match_state &, Next const &) 31 | { 32 | return true; 33 | } 34 | }; 35 | 36 | }}} 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/matchers.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // matchers.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHERS_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHERS_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | //#include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | //#include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/regex_domain.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | /// \file regex_domain.hpp 3 | /// Contains the definition of the regex_domain type 4 | // 5 | // Copyright 2009 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) 8 | 9 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_REGEX_DOMAIN_HPP_EAN_12_12_2009 10 | #define BOOST_XPRESSIVE_DETAIL_CORE_REGEX_DOMAIN_HPP_EAN_12_12_2009 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost { namespace xpressive { namespace detail 18 | { 19 | struct regex_domain 20 | : proto::domain > > 21 | {}; 22 | }}} 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/core/sub_match_impl.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // sub_match_impl.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_SUB_MATCH_IMPL_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_CORE_SUB_MATCH_IMPL_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | 18 | namespace boost { namespace xpressive { namespace detail 19 | { 20 | 21 | // TODO: sub_match_impl is a POD IFF BidiIter is POD. Pool allocation 22 | // of them can be made more efficient if they are. Or maybe all they 23 | // need is trivial constructor/destructor. (???) 24 | 25 | /////////////////////////////////////////////////////////////////////////////// 26 | // sub_match_impl 27 | // 28 | template 29 | struct sub_match_impl 30 | : sub_match 31 | { 32 | unsigned int repeat_count_; 33 | BidiIter begin_; 34 | bool zero_width_; 35 | 36 | sub_match_impl(BidiIter const &begin) 37 | : sub_match(begin, begin) 38 | , repeat_count_(0) 39 | , begin_(begin) 40 | , zero_width_(false) 41 | { 42 | } 43 | }; 44 | 45 | }}} // namespace boost::xpressive::detail 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/dynamic/parser_enum.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // parser_enum.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_DYNAMIC_PARSER_ENUM_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_DYNAMIC_PARSER_ENUM_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | namespace boost { namespace xpressive { namespace regex_constants 17 | { 18 | 19 | /////////////////////////////////////////////////////////////////////////////// 20 | // compiler_token_type 21 | // 22 | enum compiler_token_type 23 | { 24 | token_literal, 25 | token_any, // . 26 | token_escape, // 27 | token_group_begin, // ( 28 | token_group_end, // ) 29 | token_alternate, // | 30 | token_invalid_quantifier, // { 31 | token_charset_begin, // [ 32 | token_charset_end, // ] 33 | token_charset_invert, // ^ 34 | token_charset_hyphen, // - 35 | token_charset_backspace, // \b 36 | token_posix_charset_begin, // [: 37 | token_posix_charset_end, // :] 38 | token_equivalence_class_begin, // [= 39 | token_equivalence_class_end, // =] 40 | token_collation_element_begin, // [. 41 | token_collation_element_end, // .] 42 | 43 | token_quote_meta_begin, // \Q 44 | token_quote_meta_end, // \E 45 | 46 | token_no_mark, // ?: 47 | token_positive_lookahead, // ?= 48 | token_negative_lookahead, // ?! 49 | token_positive_lookbehind, // ?<= 50 | token_negative_lookbehind, // ? 52 | token_comment, // ?# 53 | token_recurse, // ?R 54 | token_rule_assign, // ?$[name]= 55 | token_rule_ref, // ?$[name] 56 | token_named_mark, // ?P 57 | token_named_mark_ref, // ?P=name 58 | 59 | token_assert_begin_sequence, // \A 60 | token_assert_end_sequence, // \Z 61 | token_assert_begin_line, // ^ 62 | token_assert_end_line, // $ 63 | token_assert_word_begin, // \< 64 | token_assert_word_end, // \> 65 | token_assert_word_boundary, // \b 66 | token_assert_not_word_boundary, // \B 67 | 68 | token_escape_newline, // \n 69 | token_escape_escape, // \e 70 | token_escape_formfeed, // \f 71 | token_escape_horizontal_tab, // \t 72 | token_escape_vertical_tab, // \v 73 | token_escape_bell, // \a 74 | token_escape_control, // \c 75 | 76 | token_end_of_pattern 77 | }; 78 | 79 | }}} // namespace boost::xpressive::regex_constants 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/static/modifier.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // modifier.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_MODIFIER_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_STATIC_MODIFIER_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | # pragma warning(push) 15 | # pragma warning(disable : 4510) // default constructor could not be generated 16 | # pragma warning(disable : 4610) // user defined constructor required 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace boost { namespace xpressive { namespace detail 24 | { 25 | 26 | /////////////////////////////////////////////////////////////////////////////// 27 | // modifier 28 | template 29 | struct modifier_op 30 | { 31 | typedef regex_constants::syntax_option_type opt_type; 32 | 33 | template 34 | struct apply 35 | { 36 | typedef typename proto::binary_expr< 37 | modifier_tag 38 | , typename proto::terminal::type 39 | , typename proto::result_of::as_child::type 40 | >::type type; 41 | }; 42 | 43 | template 44 | typename apply::type const 45 | operator ()(Expr const &expr) const 46 | { 47 | typename apply::type that = {{this->mod_}, proto::as_child(expr)}; 48 | return that; 49 | } 50 | 51 | operator opt_type() const 52 | { 53 | return this->opt_; 54 | } 55 | 56 | Modifier mod_; 57 | opt_type opt_; 58 | }; 59 | 60 | }}} 61 | 62 | #if defined(_MSC_VER) 63 | # pragma warning(pop) 64 | #endif 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/static/transforms/as_inverse.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // as_inverse.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_INVERSE_HPP_EAN_04_05_2007 9 | #define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_INVERSE_HPP_EAN_04_05_2007 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #define UNCV(x) typename remove_const::type 23 | #define UNREF(x) typename remove_reference::type 24 | #define UNCVREF(x) UNCV(UNREF(x)) 25 | 26 | namespace boost { namespace xpressive { namespace grammar_detail 27 | { 28 | 29 | template 30 | struct inverter 31 | { 32 | typedef T type; 33 | static T call(T t) 34 | { 35 | t.inverse(); 36 | return t; 37 | } 38 | }; 39 | 40 | template 41 | struct inverter > 42 | { 43 | typedef detail::literal_matcher::type> type; 44 | static type call(detail::literal_matcher t) 45 | { 46 | return type(t.ch_); 47 | } 48 | }; 49 | 50 | template 51 | struct inverter > 52 | { 53 | // ~_ln matches any one character that is not in the "newline" character class 54 | typedef detail::posix_charset_matcher type; 55 | static type call(detail::logical_newline_matcher t) 56 | { 57 | return type(t.newline(), true); 58 | } 59 | }; 60 | 61 | template 62 | struct inverter, Traits> > 63 | { 64 | typedef detail::assert_word_matcher, Traits> type; 65 | static type call(detail::assert_word_matcher, Traits> t) 66 | { 67 | return type(t.word()); 68 | } 69 | }; 70 | 71 | struct as_inverse : proto::callable 72 | { 73 | template 74 | struct result; 75 | 76 | template 77 | struct result 78 | : inverter 79 | {}; 80 | 81 | template 82 | typename inverter::type operator ()(Matcher const &matcher) const 83 | { 84 | return inverter::call(matcher); 85 | } 86 | }; 87 | 88 | }}} 89 | 90 | #undef UNCV 91 | #undef UNREF 92 | #undef UNCVREF 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/static/transforms/as_marker.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // as_marker.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_MARKER_HPP_EAN_04_01_2007 9 | #define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_MARKER_HPP_EAN_04_01_2007 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { namespace xpressive { namespace grammar_detail 21 | { 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // as_marker 25 | // Insert mark tags before and after the expression 26 | struct as_marker : proto::transform 27 | { 28 | template 29 | struct impl : proto::transform_impl 30 | { 31 | typedef 32 | typename shift_right< 33 | terminal::type 34 | , typename shift_right< 35 | typename proto::result_of::right::type 36 | , terminal::type 37 | >::type 38 | >::type 39 | result_type; 40 | 41 | result_type operator ()( 42 | typename impl::expr_param expr 43 | , typename impl::state_param 44 | , typename impl::data_param 45 | ) const 46 | { 47 | int mark_nbr = detail::get_mark_number(proto::left(expr)); 48 | detail::mark_begin_matcher begin(mark_nbr); 49 | detail::mark_end_matcher end(mark_nbr); 50 | 51 | result_type that = {{begin}, {proto::right(expr), {end}}}; 52 | return that; 53 | } 54 | }; 55 | }; 56 | }}} 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/static/transforms/as_matcher.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // as_matcher.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_MATCHER_HPP_EAN_04_01_2007 9 | #define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_MATCHER_HPP_EAN_04_01_2007 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { namespace xpressive { namespace grammar_detail 21 | { 22 | struct as_matcher : proto::transform 23 | { 24 | template 25 | struct impl : proto::transform_impl 26 | { 27 | typedef typename impl::data data_type; 28 | 29 | typedef 30 | typename data_type::template apply< 31 | typename proto::result_of::value::type 32 | >::type 33 | result_type; 34 | 35 | result_type operator ()( 36 | typename impl::expr_param expr 37 | , typename impl::state_param 38 | , typename impl::data_param data 39 | ) const 40 | { 41 | return data.call(proto::value(expr)); 42 | } 43 | }; 44 | }; 45 | 46 | }}} 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/static/transforms/as_modifier.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // as_modifier.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_MODIFIER_HPP_EAN_04_05_2007 9 | #define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_MODIFIER_HPP_EAN_04_05_2007 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #define UNCV(x) typename remove_const::type 22 | #define UNREF(x) typename remove_reference::type 23 | #define UNCVREF(x) UNCV(UNREF(x)) 24 | 25 | namespace boost { namespace xpressive { namespace detail 26 | { 27 | /////////////////////////////////////////////////////////////////////////////// 28 | // regex operator tags 29 | struct modifier_tag 30 | {}; 31 | 32 | }}} 33 | 34 | namespace boost { namespace xpressive { namespace grammar_detail 35 | { 36 | 37 | /////////////////////////////////////////////////////////////////////////////// 38 | // as_modifier 39 | template 40 | struct as_modifier : proto::transform > 41 | { 42 | template 43 | struct impl : proto::transform_impl 44 | { 45 | typedef 46 | typename proto::result_of::value< 47 | typename proto::result_of::left::type 48 | >::type 49 | modifier_type; 50 | 51 | typedef 52 | typename modifier_type::template apply::type 53 | visitor_type; 54 | 55 | typedef 56 | typename proto::result_of::right::type 57 | expr_type; 58 | 59 | typedef 60 | typename Grammar::template impl::result_type 61 | result_type; 62 | 63 | result_type operator ()( 64 | typename impl::expr_param expr 65 | , typename impl::state_param state 66 | , typename impl::data_param data 67 | ) const 68 | { 69 | visitor_type new_visitor(proto::value(proto::left(expr)).call(data)); 70 | return typename Grammar::template impl()( 71 | proto::right(expr) 72 | , state 73 | , new_visitor 74 | ); 75 | } 76 | }; 77 | }; 78 | 79 | }}} 80 | 81 | #undef UNCV 82 | #undef UNREF 83 | #undef UNCVREF 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/static/transforms/as_sequence.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // as_sequence.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_SEQUENCE_HPP_EAN_04_01_2007 9 | #define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_SEQUENCE_HPP_EAN_04_01_2007 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace boost { namespace xpressive { namespace grammar_detail 22 | { 23 | template 24 | struct in_sequence : proto::transform > 25 | { 26 | template 27 | struct impl : proto::transform_impl 28 | { 29 | typedef 30 | detail::static_xpression< 31 | typename Grammar::template impl::result_type 32 | , State 33 | > 34 | result_type; 35 | 36 | result_type operator ()( 37 | typename impl::expr_param expr 38 | , typename impl::state_param state 39 | , typename impl::data_param data 40 | ) const 41 | { 42 | return result_type( 43 | typename Grammar::template impl()(expr, state, data) 44 | , state 45 | ); 46 | } 47 | }; 48 | }; 49 | 50 | }}} 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/static/type_traits.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // type_traits.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TYPE_TRAITS_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_STATIC_TYPE_TRAITS_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | namespace boost { namespace xpressive { namespace detail 24 | { 25 | 26 | /////////////////////////////////////////////////////////////////////////////// 27 | // is_static_xpression 28 | // 29 | template 30 | struct is_static_xpression 31 | : mpl::false_ 32 | { 33 | }; 34 | 35 | template 36 | struct is_static_xpression > 37 | : mpl::true_ 38 | { 39 | }; 40 | 41 | template 42 | struct is_static_xpression > 43 | : mpl::true_ 44 | { 45 | }; 46 | 47 | ////////////////////////////////////////////////////////////////////////// 48 | // is_random 49 | // 50 | template 51 | struct is_random 52 | : is_convertible 53 | < 54 | typename iterator_category::type 55 | , std::random_access_iterator_tag 56 | > 57 | { 58 | }; 59 | 60 | ////////////////////////////////////////////////////////////////////////// 61 | // is_string_iterator 62 | // 63 | template 64 | struct is_string_iterator 65 | : mpl::false_ 66 | { 67 | }; 68 | 69 | template<> 70 | struct is_string_iterator 71 | : mpl::true_ 72 | { 73 | }; 74 | 75 | template<> 76 | struct is_string_iterator 77 | : mpl::true_ 78 | { 79 | }; 80 | 81 | #ifndef BOOST_NO_STD_WSTRING 82 | template<> 83 | struct is_string_iterator 84 | : mpl::true_ 85 | { 86 | }; 87 | 88 | template<> 89 | struct is_string_iterator 90 | : mpl::true_ 91 | { 92 | }; 93 | #endif 94 | 95 | /////////////////////////////////////////////////////////////////////////////// 96 | // is_char 97 | // 98 | template 99 | struct is_char 100 | : mpl::false_ 101 | {}; 102 | 103 | template<> 104 | struct is_char 105 | : mpl::true_ 106 | {}; 107 | 108 | template<> 109 | struct is_char 110 | : mpl::true_ 111 | {}; 112 | 113 | }}} // namespace boost::xpressive::detail 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/utility/chset/range_run.hpp: -------------------------------------------------------------------------------- 1 | /*============================================================================= 2 | Copyright (c) 2001-2003 Joel de Guzman 3 | http://spirit.sourceforge.net/ 4 | 5 | Use, modification and distribution is subject to the Boost Software 6 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | http://www.boost.org/LICENSE_1_0.txt) 8 | =============================================================================*/ 9 | #ifndef BOOST_XPRESSIVE_SPIRIT_RANGE_RUN_HPP_EAN_10_04_2005 10 | #define BOOST_XPRESSIVE_SPIRIT_RANGE_RUN_HPP_EAN_10_04_2005 11 | 12 | /////////////////////////////////////////////////////////////////////////////// 13 | #include 14 | 15 | /////////////////////////////////////////////////////////////////////////////// 16 | namespace boost { namespace xpressive { namespace detail 17 | { 18 | 19 | /////////////////////////////////////////////////////////////////////////// 20 | // 21 | // range class 22 | // 23 | // Implements a closed range of values. This class is used in 24 | // the implementation of the range_run class. 25 | // 26 | // { Low level implementation detail } 27 | // { Not to be confused with spirit::range } 28 | // 29 | /////////////////////////////////////////////////////////////////////////// 30 | template 31 | struct range 32 | { 33 | range(Char first, Char last); 34 | 35 | bool is_valid() const; 36 | bool includes(Char v) const; 37 | bool includes(range const &r) const; 38 | bool overlaps(range const &r) const; 39 | void merge(range const &r); 40 | 41 | Char first_; 42 | Char last_; 43 | }; 44 | 45 | ////////////////////////////////// 46 | template 47 | struct range_compare 48 | { 49 | bool operator()(range const &x, range const &y) const 50 | { 51 | return x.first_ < y.first_; 52 | } 53 | }; 54 | 55 | /////////////////////////////////////////////////////////////////////////// 56 | // 57 | // range_run 58 | // 59 | // An implementation of a sparse bit (boolean) set. The set uses 60 | // a sorted vector of disjoint ranges. This class implements the 61 | // bare minimum essentials from which the full range of set 62 | // operators can be implemented. The set is constructed from 63 | // ranges. Internally, adjacent or overlapping ranges are 64 | // coalesced. 65 | // 66 | // range_runs are very space-economical in situations where there 67 | // are lots of ranges and a few individual disjoint values. 68 | // Searching is O(log n) where n is the number of ranges. 69 | // 70 | // { Low level implementation detail } 71 | // 72 | /////////////////////////////////////////////////////////////////////////// 73 | template 74 | struct range_run 75 | { 76 | typedef range range_type; 77 | typedef std::vector run_type; 78 | typedef typename run_type::iterator iterator; 79 | typedef typename run_type::const_iterator const_iterator; 80 | 81 | void swap(range_run& rr); 82 | bool empty() const; 83 | bool test(Char v) const; 84 | template 85 | bool test(Char v, Traits const &tr) const; 86 | void set(range_type const &r); 87 | void clear(range_type const &r); 88 | void clear(); 89 | 90 | const_iterator begin() const; 91 | const_iterator end() const; 92 | 93 | private: 94 | void merge(iterator iter, range_type const &r); 95 | 96 | run_type run_; 97 | }; 98 | 99 | }}} // namespace boost::xpressive::detail 100 | 101 | #endif 102 | 103 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/utility/counted_base.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // (c) Copyright Andreas Huber Doenni 2002-2005, Eric Niebler 2006 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_COUNTED_BASE_HPP_EAN_04_16_2006 8 | #define BOOST_XPRESSIVE_DETAIL_UTILITY_COUNTED_BASE_HPP_EAN_04_16_2006 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace boost { namespace xpressive { namespace detail 15 | { 16 | template 17 | struct counted_base_access; 18 | 19 | ////////////////////////////////////////////////////////////////////////////// 20 | // counted_base 21 | template 22 | struct counted_base 23 | { 24 | long use_count() const 25 | { 26 | return this->count_; 27 | } 28 | 29 | protected: 30 | counted_base() 31 | : count_(0) 32 | { 33 | } 34 | 35 | counted_base(counted_base const &) 36 | : count_(0) 37 | { 38 | } 39 | 40 | counted_base &operator =(counted_base const &) 41 | { 42 | return *this; 43 | } 44 | 45 | private: 46 | friend struct counted_base_access; 47 | mutable boost::detail::atomic_count count_; 48 | }; 49 | 50 | ////////////////////////////////////////////////////////////////////////////// 51 | // counted_base_access 52 | template 53 | struct counted_base_access 54 | { 55 | static void add_ref(counted_base const *that) 56 | { 57 | ++that->count_; 58 | } 59 | 60 | static void release(counted_base const *that) 61 | { 62 | BOOST_ASSERT(0 < that->count_); 63 | if(0 == --that->count_) 64 | { 65 | boost::checked_delete(static_cast(that)); 66 | } 67 | } 68 | }; 69 | 70 | template 71 | inline void intrusive_ptr_add_ref(counted_base const *that) 72 | { 73 | counted_base_access::add_ref(that); 74 | } 75 | 76 | template 77 | inline void intrusive_ptr_release(counted_base const *that) 78 | { 79 | counted_base_access::release(that); 80 | } 81 | 82 | }}} // namespace boost::xpressive::detail 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/utility/dont_care.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // dont_care.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_DONT_CARE_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_UTILITY_DONT_CARE_HPP_EAN_10_04_2005 10 | 11 | namespace boost { namespace xpressive { namespace detail 12 | { 13 | /////////////////////////////////////////////////////////////////////////////// 14 | // for function arguments we don't care about 15 | struct dont_care 16 | { 17 | dont_care() {} 18 | 19 | template 20 | dont_care(T const &) {} 21 | }; 22 | 23 | }}} 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/utility/ignore_unused.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // ignore_unused.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_IGNORE_UNUSED_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_UTILITY_IGNORE_UNUSED_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include "boost/proto/detail/ignore_unused.hpp" 17 | 18 | namespace boost { namespace xpressive { namespace detail 19 | { 20 | using boost::proto::detail::ignore_unused; 21 | }}} 22 | 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/utility/literals.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // literals.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_LITERALS_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_UTILITY_LITERALS_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include // for BOOST_STATIC_CONSTANT 17 | #include // for BOOST_STATIC_CONSTANT 18 | #include 19 | 20 | namespace boost { namespace xpressive { namespace detail 21 | { 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // char_literal 25 | // 26 | template 27 | struct char_literal; 28 | 29 | template 30 | struct char_literal 31 | { 32 | BOOST_STATIC_CONSTANT(boost::intmax_t, value = Ch); 33 | }; 34 | 35 | #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION 36 | template 37 | boost::intmax_t const char_literal::value; 38 | #endif 39 | 40 | template 41 | struct string_literal; 42 | 43 | template<> 44 | struct string_literal 45 | { 46 | static BOOST_CONSTEXPR char const *pick(char const *cstr, wchar_t const *) 47 | { 48 | return cstr; 49 | } 50 | 51 | static BOOST_CONSTEXPR char pick(char ch, wchar_t) 52 | { 53 | return ch; 54 | } 55 | }; 56 | 57 | template<> 58 | struct string_literal 59 | { 60 | static BOOST_CONSTEXPR wchar_t const *pick(char const *, wchar_t const *cstr) 61 | { 62 | return cstr; 63 | } 64 | 65 | static BOOST_CONSTEXPR wchar_t pick(char, wchar_t ch) 66 | { 67 | return ch; 68 | } 69 | }; 70 | 71 | #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206)) 72 | 73 | # define BOOST_XPR_CHAR_(Char, ch) ch 74 | # define BOOST_XPR_CSTR_(Char, st) boost::xpressive::detail::string_literal::pick(st, L##st) 75 | 76 | #else 77 | 78 | # define BOOST_XPR_CHAR_(Char, ch) boost::xpressive::detail::char_literal::value 79 | # define BOOST_XPR_CSTR_(Char, st) boost::xpressive::detail::string_literal::pick(st, L##st) 80 | 81 | #endif 82 | 83 | }}} // namespace boost::xpressive::detail 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/utility/never_true.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // never_true.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_NEVER_TRUE_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_UTILITY_NEVER_TRUE_HPP_EAN_10_04_2005 10 | 11 | #include 12 | 13 | namespace boost { namespace xpressive { namespace detail 14 | { 15 | 16 | // for use in static asserts 17 | template 18 | struct never_true 19 | : mpl::false_ 20 | { 21 | }; 22 | 23 | }}} 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/utility/save_restore.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // save_restore.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_SAVE_RESTORE_HPP_EAN_10_04_2005 9 | #define BOOST_XPRESSIVE_DETAIL_UTILITY_SAVE_RESTORE_HPP_EAN_10_04_2005 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include 17 | 18 | namespace boost { namespace xpressive { namespace detail 19 | { 20 | 21 | template 22 | struct save_restore 23 | : private noncopyable 24 | { 25 | explicit save_restore(T &t) 26 | : ref(t) 27 | , val(t) 28 | { 29 | } 30 | 31 | save_restore(T &t, T const &n) 32 | : ref(t) 33 | , val(t) 34 | { 35 | this->ref = n; 36 | } 37 | 38 | ~save_restore() 39 | { 40 | this->ref = this->val; 41 | } 42 | 43 | void restore() 44 | { 45 | this->ref = this->val; 46 | } 47 | 48 | private: 49 | T &ref; 50 | T const val; 51 | }; 52 | 53 | }}} 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /include/boost/xpressive/detail/utility/width.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // width.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_WIDTH_HPP_EAN_04_07_2006 9 | #define BOOST_XPRESSIVE_DETAIL_UTILITY_WIDTH_HPP_EAN_04_07_2006 10 | 11 | // MS compatible compilers support #pragma once 12 | #if defined(_MSC_VER) 13 | # pragma once 14 | #endif 15 | 16 | #include // for INT_MAX 17 | #include 18 | 19 | namespace boost { namespace xpressive { namespace detail 20 | { 21 | 22 | typedef mpl::size_t unknown_width; 23 | struct width; 24 | bool is_unknown(width const &that); 25 | 26 | /////////////////////////////////////////////////////////////////////////////// 27 | // width 28 | struct width 29 | { 30 | width(std::size_t val = 0) 31 | : value_(val) 32 | { 33 | } 34 | 35 | bool operator !() const 36 | { 37 | return !this->value_; 38 | } 39 | 40 | width &operator +=(width const &that) 41 | { 42 | this->value_ = 43 | !is_unknown(*this) && !is_unknown(that) 44 | ? this->value_ + that.value_ 45 | : unknown_width(); 46 | return *this; 47 | } 48 | 49 | width &operator |=(width const &that) 50 | { 51 | this->value_ = 52 | this->value_ == that.value_ 53 | ? this->value_ 54 | : unknown_width(); 55 | return *this; 56 | } 57 | 58 | std::size_t value() const 59 | { 60 | return this->value_; 61 | } 62 | 63 | private: 64 | std::size_t value_; 65 | }; 66 | 67 | inline bool is_unknown(width const &that) 68 | { 69 | return unknown_width::value == that.value(); 70 | } 71 | 72 | inline bool operator ==(width const &left, width const &right) 73 | { 74 | return left.value() == right.value(); 75 | } 76 | 77 | inline bool operator !=(width const &left, width const &right) 78 | { 79 | return left.value() != right.value(); 80 | } 81 | 82 | inline width operator +(width left, width const &right) 83 | { 84 | return left += right; 85 | } 86 | 87 | inline width operator |(width left, width const &right) 88 | { 89 | return left |= right; 90 | } 91 | 92 | }}} // namespace boost::xpressive::detail 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /include/boost/xpressive/regex_traits.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | /// \file regex_traits.hpp 3 | /// Includes the C regex traits or the CPP regex traits header file depending on the 4 | /// BOOST_XPRESSIVE_USE_C_TRAITS macro. 5 | // 6 | // Copyright 2008 Eric Niebler. Distributed under the Boost 7 | // 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 | #ifndef BOOST_XPRESSIVE_REGEX_TRAITS_HPP_EAN_10_04_2005 11 | #define BOOST_XPRESSIVE_REGEX_TRAITS_HPP_EAN_10_04_2005 12 | 13 | // MS compatible compilers support #pragma once 14 | #if defined(_MSC_VER) 15 | # pragma once 16 | #endif 17 | 18 | #include 19 | #include 20 | 21 | #ifdef BOOST_XPRESSIVE_USE_C_TRAITS 22 | # include 23 | #else 24 | # include 25 | #endif 26 | 27 | namespace boost { namespace xpressive 28 | { 29 | 30 | /////////////////////////////////////////////////////////////////////////////// 31 | // regex_traits_version_1_tag 32 | /// Tag used to denote that a traits class conforms to the version 1 traits 33 | /// interface. 34 | struct regex_traits_version_1_tag 35 | { 36 | }; 37 | 38 | /////////////////////////////////////////////////////////////////////////////// 39 | // regex_traits_version_2_tag 40 | /// Tag used to denote that a traits class conforms to the version 2 traits 41 | /// interface. 42 | struct regex_traits_version_2_tag 43 | : regex_traits_version_1_tag 44 | { 45 | }; 46 | 47 | /////////////////////////////////////////////////////////////////////////////// 48 | // regex_traits_version_1_case_fold_tag DEPRECATED use has_fold_case trait 49 | /// INTERNAL ONLY 50 | /// 51 | struct regex_traits_version_1_case_fold_tag 52 | : regex_traits_version_1_tag 53 | { 54 | }; 55 | 56 | /////////////////////////////////////////////////////////////////////////////// 57 | // has_fold_case 58 | /// Trait used to denote that a traits class has the fold_case member function. 59 | template 60 | struct has_fold_case 61 | : is_convertible< 62 | typename Traits::version_tag * 63 | , regex_traits_version_1_case_fold_tag * 64 | > 65 | { 66 | }; 67 | 68 | /////////////////////////////////////////////////////////////////////////////// 69 | // regex_traits 70 | /// Thin wrapper around the default regex_traits implementation, either 71 | /// cpp_regex_traits or c_regex_traits 72 | /// 73 | template 74 | struct regex_traits 75 | : Impl 76 | { 77 | typedef typename Impl::locale_type locale_type; 78 | 79 | regex_traits() 80 | : Impl() 81 | { 82 | } 83 | 84 | explicit regex_traits(locale_type const &loc) 85 | : Impl(loc) 86 | { 87 | } 88 | }; 89 | 90 | /////////////////////////////////////////////////////////////////////////////// 91 | // lookup_classname 92 | /// INTERNAL ONLY 93 | template 94 | inline typename Traits::char_class_type 95 | lookup_classname(Traits const &traits, char const (&cname)[N], bool icase) 96 | { 97 | typename Traits::char_type name[N] = {0}; 98 | for(std::size_t j = 0; j < N-1; ++j) 99 | { 100 | name[j] = traits.widen(cname[j]); 101 | } 102 | return traits.lookup_classname(name, name + N - 1, icase); 103 | } 104 | 105 | }} 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /include/boost/xpressive/xpressive.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | /// \file xpressive.hpp 3 | /// Includes all of xpressive including support for both static and 4 | /// dynamic regular expressions. 5 | // 6 | // Copyright 2008 Eric Niebler. Distributed under the Boost 7 | // 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 | #ifndef BOOST_XPRESSIVE_HPP_EAN_10_04_2005 11 | #define BOOST_XPRESSIVE_HPP_EAN_10_04_2005 12 | 13 | // MS compatible compilers support #pragma once 14 | #if defined(_MSC_VER) 15 | # pragma once 16 | #endif 17 | 18 | #include 19 | #include 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /include/boost/xpressive/xpressive_dynamic.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | /// \file xpressive_dynamic.hpp 3 | /// Includes everything you need to write and use dynamic regular expressions. 4 | // 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) 8 | 9 | #ifndef BOOST_XPRESSIVE_DYNAMIC_HPP_EAN_10_04_2005 10 | #define BOOST_XPRESSIVE_DYNAMIC_HPP_EAN_10_04_2005 11 | 12 | // MS compatible compilers support #pragma once 13 | #if defined(_MSC_VER) 14 | # pragma once 15 | #endif 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /include/boost/xpressive/xpressive_static.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | /// \file xpressive_static.hpp 3 | /// Includes everything you need to write static regular expressions and use 4 | /// them. 5 | // 6 | // Copyright 2008 Eric Niebler. Distributed under the Boost 7 | // 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 | #ifndef BOOST_XPRESSIVE_STATIC_HPP_EAN_10_04_2005 11 | #define BOOST_XPRESSIVE_STATIC_HPP_EAN_10_04_2005 12 | 13 | // MS compatible compilers support #pragma once 14 | #if defined(_MSC_VER) 15 | # pragma once 16 | #endif 17 | 18 | #if defined(_MSC_VER) && !defined(__clang__) 19 | // inline aggressively 20 | # pragma inline_recursion(on) // turn on inline recursion 21 | # pragma inline_depth(255) // max inline depth 22 | #endif 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Automatic redirection failed, please go to 7 | ../../doc/html/xpressive.html 8 |

Copyright Eric Niebler 2006

9 |

Distributed under the Boost Software License, Version 1.0. (See accompanying file 10 | LICENSE_1_0.txt or copy at 11 | www.boost.org/LICENSE_1_0.txt). 12 |

13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /meta/libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "xpressive", 3 | "name": "Xpressive", 4 | "authors": [ 5 | "Eric Niebler" 6 | ], 7 | "description": "Regular expressions that can be written as strings or as expression templates, and which can refer to each other and themselves recursively with the power of context-free grammars.", 8 | "category": [ 9 | "String" 10 | ], 11 | "maintainers": [ 12 | "Eric Niebler " 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /perf/Jamfile.v2: -------------------------------------------------------------------------------- 1 | # Copyright Eric Niebler 2006 2 | 3 | # Use, modification, and distribution is subject to the Boost Software 4 | # License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | # http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | project : requirements /boost/xpressive//boost_xpressive ; 8 | 9 | exe xprperf 10 | : 11 | command_line.cpp 12 | main.cpp 13 | time_boost.cpp 14 | time_dynamic_xpressive.cpp 15 | time_static_xpressive.cpp 16 | /boost/regex//boost_regex 17 | /boost/timer//boost_timer 18 | /boost/test//boost_unit_test_framework 19 | : 20 | BOOST_XPRESSIVE_USE_CPP_TRAITS 21 | BOOST_TIMER_ENABLE_DEPRECATED 22 | ; 23 | -------------------------------------------------------------------------------- /perf/gcc/long_twain_search.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | Long Searches 9 | 10 | 11 | 12 | static xpressivedynamic xpressiveBoostExpression 13 | 14 | 15 | 16 | 17 | 1(0.0263s)1(0.0263s)1.78(0.0469s)Twain 18 | 19 | 20 | 1(0.0234s)1(0.0234s)1.79(0.042s)Huck[[:alpha:]]+ 21 | 22 | 23 | 1.84(1.26s)2.21(1.51s)1(0.687s)[[:alpha:]]+ing 24 | 25 | 26 | 1.09(0.192s)2(0.351s)1(0.176s)^[^ 27 | ]*?Twain 28 | 29 | 30 | 1.41(0.08s)1.21(0.0684s)1(0.0566s)Tom|Sawyer|Huckleberry|Finn 31 | 32 | 33 | 1.56(0.195s)1.12(0.141s)1(0.125s)(Tom|Sawyer|Huckleberry|Finn).{0,30}river|river.{0,30}(Tom|Sawyer|Huckleberry|Finn) 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /perf/gcc/short_twain_search.xml: -------------------------------------------------------------------------------- 1 | 7 | Results not available... 8 | -------------------------------------------------------------------------------- /perf/msvc/long_twain_search.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | Long Searches 9 | 10 | 11 | 12 | static xpressivedynamic xpressiveBoostExpression 13 | 14 | 15 | 16 | 17 | 1(0.019s)1(0.019s)2.98(0.0566s)Twain 18 | 19 | 20 | 1(0.0176s)1(0.0176s)3.17(0.0556s)Huck[[:alpha:]]+ 21 | 22 | 23 | 3.62(1.78s)3.97(1.95s)1(0.492s)[[:alpha:]]+ing 24 | 25 | 26 | 2.32(0.344s)3.06(0.453s)1(0.148s)^[^ 27 | ]*?Twain 28 | 29 | 30 | 1(0.0576s)1.05(0.0606s)1.15(0.0664s)Tom|Sawyer|Huckleberry|Finn 31 | 32 | 33 | 1.24(0.164s)1.44(0.191s)1(0.133s)(Tom|Sawyer|Huckleberry|Finn).{0,30}river|river.{0,30}(Tom|Sawyer|Huckleberry|Finn) 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /perf/msvc/short_twain_search.xml: -------------------------------------------------------------------------------- 1 | 7 | Results not available... 8 | -------------------------------------------------------------------------------- /perf/time_boost.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2002 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 | #include "./regex_comparison.hpp" 13 | #include 14 | #include 15 | 16 | namespace b{ 17 | 18 | double time_match(const std::string& re, const std::string& text) 19 | { 20 | boost::regex e(re, boost::regex_constants::ECMAScript | boost::regex_constants::optimize); 21 | boost::smatch what; 22 | boost::timer tim; 23 | int iter = 1; 24 | int counter, repeats; 25 | double result = 0; 26 | double run; 27 | do 28 | { 29 | tim.restart(); 30 | for(counter = 0; counter < iter; ++counter) 31 | { 32 | boost::regex_match(text, what, e); 33 | } 34 | result = tim.elapsed(); 35 | iter *= 2; 36 | }while(result < 0.5); 37 | iter /= 2; 38 | 39 | // repeat test and report least value for consistency: 40 | for(repeats = 0; repeats < REPEAT_COUNT; ++repeats) 41 | { 42 | tim.restart(); 43 | for(counter = 0; counter < iter; ++counter) 44 | { 45 | boost::regex_match(text, what, e); 46 | } 47 | run = tim.elapsed(); 48 | result = (std::min)(run, result); 49 | } 50 | return result / iter; 51 | } 52 | 53 | //bool dummy_grep_proc(const boost::smatch&) 54 | //{ return true; } 55 | 56 | struct noop 57 | { 58 | void operator()( boost::smatch const & ) const 59 | { 60 | } 61 | }; 62 | 63 | double time_find_all(const std::string& re, const std::string& text) 64 | { 65 | boost::regex e(re, boost::regex_constants::ECMAScript | boost::regex_constants::optimize); 66 | boost::smatch what; 67 | boost::timer tim; 68 | int iter = 1; 69 | int counter, repeats; 70 | double result = 0; 71 | double run; 72 | do 73 | { 74 | tim.restart(); 75 | for(counter = 0; counter < iter; ++counter) 76 | { 77 | boost::sregex_iterator begin( text.begin(), text.end(), e ), end; 78 | std::for_each( begin, end, noop() ); 79 | //boost::regex_grep(&dummy_grep_proc, text, e); 80 | } 81 | result = tim.elapsed(); 82 | iter *= 2; 83 | }while(result < 0.5); 84 | iter /= 2; 85 | 86 | if(result >10) 87 | return result / iter; 88 | 89 | // repeat test and report least value for consistency: 90 | for(repeats = 0; repeats < REPEAT_COUNT; ++repeats) 91 | { 92 | tim.restart(); 93 | for(counter = 0; counter < iter; ++counter) 94 | { 95 | boost::sregex_iterator begin( text.begin(), text.end(), e ), end; 96 | std::for_each( begin, end, noop() ); 97 | //boost::regex_grep(&dummy_grep_proc, text, e); 98 | } 99 | run = tim.elapsed(); 100 | result = (std::min)(run, result); 101 | } 102 | return result / iter; 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /perf/time_dynamic_xpressive.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2002 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 | #include "./regex_comparison.hpp" 13 | #include 14 | #include 15 | #include 16 | 17 | namespace dxpr 18 | { 19 | 20 | double time_match(const std::string& re, const std::string& text) 21 | { 22 | boost::xpressive::sregex e(boost::xpressive::sregex::compile(re, boost::xpressive::regex_constants::optimize)); 23 | boost::xpressive::smatch what; 24 | boost::timer tim; 25 | int iter = 1; 26 | int counter, repeats; 27 | double result = 0; 28 | double run; 29 | assert(boost::xpressive::regex_match( text, what, e )); 30 | do 31 | { 32 | tim.restart(); 33 | for(counter = 0; counter < iter; ++counter) 34 | { 35 | boost::xpressive::regex_match( text, what, e ); 36 | } 37 | result = tim.elapsed(); 38 | iter *= 2; 39 | } while(result < 0.5); 40 | iter /= 2; 41 | 42 | // repeat test and report least value for consistency: 43 | for(repeats = 0; repeats < REPEAT_COUNT; ++repeats) 44 | { 45 | tim.restart(); 46 | for(counter = 0; counter < iter; ++counter) 47 | { 48 | boost::xpressive::regex_match( text, what, e ); 49 | } 50 | run = tim.elapsed(); 51 | result = (std::min)(run, result); 52 | } 53 | return result / iter; 54 | } 55 | 56 | struct noop 57 | { 58 | void operator()( boost::xpressive::smatch const & ) const 59 | { 60 | } 61 | }; 62 | 63 | double time_find_all(const std::string& re, const std::string& text) 64 | { 65 | boost::xpressive::sregex e(boost::xpressive::sregex::compile(re, boost::xpressive::regex_constants::optimize)); 66 | boost::xpressive::smatch what; 67 | boost::timer tim; 68 | int iter = 1; 69 | int counter, repeats; 70 | double result = 0; 71 | double run; 72 | do 73 | { 74 | tim.restart(); 75 | for(counter = 0; counter < iter; ++counter) 76 | { 77 | boost::xpressive::sregex_iterator begin( text.begin(), text.end(), e ), end; 78 | std::for_each( begin, end, noop() ); 79 | } 80 | result = tim.elapsed(); 81 | iter *= 2; 82 | }while(result < 0.5); 83 | iter /= 2; 84 | 85 | if(result >10) 86 | return result / iter; 87 | 88 | // repeat test and report least value for consistency: 89 | for(repeats = 0; repeats < REPEAT_COUNT; ++repeats) 90 | { 91 | tim.restart(); 92 | for(counter = 0; counter < iter; ++counter) 93 | { 94 | boost::xpressive::sregex_iterator begin( text.begin(), text.end(), e ), end; 95 | std::for_each( begin, end, noop() ); 96 | } 97 | run = tim.elapsed(); 98 | result = (std::min)(run, result); 99 | } 100 | return result / iter; 101 | } 102 | 103 | } 104 | 105 | 106 | -------------------------------------------------------------------------------- /test/Jamfile.v2: -------------------------------------------------------------------------------- 1 | # (C) Copyright 2004: Eric Niebler 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | 5 | # bring in rules for testing 6 | import testing ; 7 | 8 | project 9 | : requirements 10 | /boost/xpressive//boost_xpressive 11 | intel:off 12 | # Turn off debug symbols on MSVC to bring down the size of object files 13 | msvc:off 14 | msvc-8.0:_SCL_SECURE_NO_DEPRECATE 15 | msvc-8.0:_CRT_SECURE_NO_DEPRECATE 16 | msvc-9.0:_SCL_SECURE_NO_DEPRECATE 17 | msvc-10.0:_SCL_SECURE_NO_WARNINGS 18 | msvc-11.0:_SCL_SECURE_NO_DEPRECATE 19 | msvc-11.0:_SCL_SECURE_NO_WARNINGS 20 | gcc:-ftemplate-depth-1024 21 | darwin:-ftemplate-depth-1024 22 | # gcc:-W 23 | # gcc:-Wall 24 | # msvc:-W4 25 | msvc,stlport:_STLP_EXPOSE_GLOBALS_IMPLEMENTATION 26 | /boost/test//boost_unit_test_framework 27 | static 28 | ; 29 | 30 | test-suite "xpressive" 31 | : [ run regress.cpp : : regress.txt : msvc:/bigobj ] 32 | [ run regress_u.cpp : : regress.txt : msvc:/bigobj ] 33 | [ run c_traits.cpp : : regress.txt : msvc:/bigobj ] 34 | [ run c_traits_u.cpp : : regress.txt : msvc:/bigobj ] 35 | [ run test1.cpp ] 36 | [ run test2.cpp ] 37 | [ run test3.cpp ] 38 | [ run test4.cpp ] 39 | [ run test5.cpp ] 40 | [ run test6.cpp ] 41 | [ run test7.cpp ] 42 | [ run test8.cpp ] 43 | [ run test9.cpp ] 44 | [ run test10.cpp ] 45 | [ run test11.cpp ] 46 | [ run test1u.cpp ] 47 | [ run test2u.cpp ] 48 | [ run test3u.cpp ] 49 | [ run test4u.cpp ] 50 | [ run test5u.cpp ] 51 | [ run test6u.cpp ] 52 | [ run test7u.cpp ] 53 | [ run test8u.cpp ] 54 | [ run test9u.cpp ] 55 | [ run test10u.cpp ] 56 | [ run test11u.cpp ] 57 | [ run misc1.cpp ] 58 | [ run misc2.cpp ] 59 | [ run test_format.cpp ] 60 | [ run test_cycles.cpp ] 61 | [ run test_non_char.cpp ] 62 | [ run test_static.cpp ] 63 | [ run test_actions.cpp ] 64 | [ run test_assert.cpp ] 65 | [ run test_assert_with_placeholder.cpp ] 66 | [ run test_symbols.cpp ] 67 | [ run test_dynamic.cpp ] 68 | [ run test_dynamic_grammar.cpp ] 69 | [ run test_skip.cpp ] 70 | [ link multiple_defs1.cpp multiple_defs2.cpp : : multiple_defs ] 71 | [ compile test_basic_regex.cpp ] 72 | [ compile test_match_results.cpp ] 73 | [ compile test_regex_algorithms.cpp ] 74 | [ compile test_regex_compiler.cpp ] 75 | [ compile test_regex_constants.cpp ] 76 | [ compile test_regex_error.cpp ] 77 | [ compile test_regex_iterator.cpp ] 78 | [ compile test_regex_primitives.cpp ] 79 | [ compile test_regex_token_iterator.cpp ] 80 | [ compile test_regex_traits.cpp ] 81 | [ compile test_sub_match.cpp ] 82 | # [ compile test_typeof.cpp ] 83 | # [ compile test_typeof2.cpp ] 84 | ; 85 | 86 | -------------------------------------------------------------------------------- /test/c_traits.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // c_traits.cpp 3 | // 4 | // (C) Copyright Eric Niebler 2004. 5 | // Use, modification and distribution are subject to the 6 | // Boost Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | /* 10 | Revision history: 11 | 6 January 2006 : Initial version. 12 | */ 13 | 14 | #define BOOST_XPRESSIVE_USE_C_TRAITS 15 | #include "./regress.ipp" 16 | 17 | -------------------------------------------------------------------------------- /test/c_traits_u.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // c_traits.cpp 3 | // 4 | // (C) Copyright Eric Niebler 2004. 5 | // Use, modification and distribution are subject to the 6 | // Boost Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | /* 10 | Revision history: 11 | 6 January 2006 : Initial version. 12 | */ 13 | 14 | #define BOOST_XPRESSIVE_USE_C_TRAITS 15 | #define BOOST_XPRESSIVE_TEST_WREGEX 16 | #include "./regress.ipp" 17 | 18 | -------------------------------------------------------------------------------- /test/misc2.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // misc2.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace xpr = boost::xpressive; 15 | using namespace xpr; 16 | 17 | /////////////////////////////////////////////////////////////////////////////// 18 | // 19 | void test_complement() 20 | { 21 | sregex rx1 = ~_n >> ~(set='a') >> ~(set='a','b') >> ~set['a'] >> ~_ln 22 | >> ~before('a') >> ~after('a') >> ~alpha >> ~range('a','b') >> ~_b >> ~as_xpr('a'); 23 | 24 | #ifndef BOOST_XPRESSIVE_NO_WREGEX 25 | wsregex rx2 = ~_n >> ~(set=L'a') >> ~(set=L'a',L'b') >> ~set[L'a'] >> ~_ln 26 | >> ~before(L'a') >> ~after(L'a') >> ~alpha >> ~range(L'a',L'b') >> ~_b >> ~as_xpr(L'a'); 27 | #endif 28 | } 29 | 30 | /////////////////////////////////////////////////////////////////////////////// 31 | // 32 | void test_static_actions_in_dynamic_keep() 33 | { 34 | std::string result; 35 | std::string str("foo"); 36 | 37 | sregex_compiler compiler; 38 | compiler["rx0"] = (s1="foo")[ xpr::ref(result) = s1 ]; 39 | sregex rx = compiler.compile("(?>(?$rx0))"); 40 | 41 | bool ok = regex_match(str, rx); 42 | BOOST_CHECK(ok); 43 | BOOST_CHECK_EQUAL(result, "foo"); 44 | } 45 | 46 | /////////////////////////////////////////////////////////////////////////////// 47 | // 48 | void test_static_actions_in_static_keep() 49 | { 50 | std::string result; 51 | std::string str("foo"); 52 | 53 | sregex rx0 = (s1="foo")[ xpr::ref(result) = s1 ]; 54 | sregex rx = keep(rx0); 55 | 56 | bool ok = regex_match(str, rx); 57 | BOOST_CHECK(ok); 58 | BOOST_CHECK_EQUAL(result, "foo"); 59 | } 60 | 61 | /////////////////////////////////////////////////////////////////////////////// 62 | // 63 | void test_replace_with_lambda() 64 | { 65 | std::map replacements; 66 | replacements["X"] = "this"; 67 | replacements["Y"] = "that"; 68 | 69 | std::string input("\"$(X)\" has the value \"$(Y)\""), output; 70 | std::string expected("\"this\" has the value \"that\""); 71 | sregex rx = "$(" >> (s1= +~as_xpr(')')) >> ')'; 72 | 73 | output = regex_replace(input, rx, xpr::ref(replacements)[s1]); 74 | BOOST_CHECK_EQUAL(output, expected); 75 | } 76 | 77 | using namespace boost::unit_test; 78 | /////////////////////////////////////////////////////////////////////////////// 79 | // init_unit_test_suite 80 | // 81 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 82 | { 83 | test_suite *test = BOOST_TEST_SUITE("miscelaneous tests"); 84 | 85 | test->add(BOOST_TEST_CASE(&test_complement)); 86 | test->add(BOOST_TEST_CASE(&test_static_actions_in_dynamic_keep)); 87 | test->add(BOOST_TEST_CASE(&test_static_actions_in_static_keep)); 88 | test->add(BOOST_TEST_CASE(&test_replace_with_lambda)); 89 | 90 | return test; 91 | } 92 | -------------------------------------------------------------------------------- /test/multiple_defs1.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // multiple_defs1.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | extern int f(); 10 | int main() 11 | { 12 | using namespace boost::xpressive; 13 | sregex srx = +_; 14 | sregex drx = sregex::compile(".+"); 15 | return f(); 16 | } 17 | -------------------------------------------------------------------------------- /test/multiple_defs2.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // multiple_defs2.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | 10 | int f() 11 | { 12 | using namespace boost::xpressive; 13 | sregex srx = +_; 14 | sregex drx = sregex::compile(".+"); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/regress.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // regress.cpp 3 | // 4 | // (C) Copyright Eric Niebler 2004. 5 | // Use, modification and distribution are subject to the 6 | // Boost Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | /* 10 | Revision history: 11 | 6 January 2006 : Initial version. 12 | */ 13 | 14 | #include "./regress.ipp" 15 | -------------------------------------------------------------------------------- /test/regress_u.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // regress_u.cpp 3 | // 4 | // (C) Copyright Eric Niebler 2004. 5 | // Use, modification and distribution are subject to the 6 | // Boost Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | /* 10 | Revision history: 11 | 6 January 2006 : Initial version. 12 | */ 13 | 14 | #define BOOST_XPRESSIVE_TEST_WREGEX 15 | #include "./regress.ipp" 16 | -------------------------------------------------------------------------------- /test/test1.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test1.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test1.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | typedef std::string::const_iterator iterator_type; 17 | boost::iterator_range const *> rng = get_test_cases(); 18 | std::for_each(rng.begin(), rng.end(), test_runner()); 19 | } 20 | 21 | /////////////////////////////////////////////////////////////////////////////// 22 | // init_unit_test_suite 23 | // 24 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 25 | { 26 | test_suite *test = BOOST_TEST_SUITE("test1"); 27 | test->add(BOOST_TEST_CASE(&test_main)); 28 | return test; 29 | } 30 | -------------------------------------------------------------------------------- /test/test10.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test10.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test10.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | typedef std::string::const_iterator iterator_type; 17 | boost::iterator_range const *> rng = get_test_cases(); 18 | std::for_each(rng.begin(), rng.end(), test_runner()); 19 | } 20 | 21 | /////////////////////////////////////////////////////////////////////////////// 22 | // init_unit_test_suite 23 | // 24 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 25 | { 26 | test_suite *test = BOOST_TEST_SUITE("test10"); 27 | test->add(BOOST_TEST_CASE(&test_main)); 28 | return test; 29 | } 30 | -------------------------------------------------------------------------------- /test/test10.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test10.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include "./test.hpp" 9 | 10 | /////////////////////////////////////////////////////////////////////////////// 11 | // get_test_cases 12 | // 13 | template 14 | boost::iterator_range const *> get_test_cases() 15 | { 16 | typedef typename boost::iterator_value::type char_type; 17 | typedef xpr_test_case xpr_test_case; 18 | typedef basic_regex regex_type; 19 | 20 | static char_type const *nilbr = 0; 21 | static xpr_test_case const test_cases[] = 22 | { 23 | xpr_test_case 24 | ( 25 | "test16" 26 | , L("foobarboo") 27 | , regex_type(L('b') >> +_ >> L("ar") >> eos) 28 | , no_match 29 | ) 30 | , xpr_test_case 31 | ( 32 | "test17" 33 | , L("foobarboo") 34 | , regex_type(L('b') >> +_ >> L('o') >> eos) 35 | , backrefs(L("barboo"), nilbr) 36 | ) 37 | , xpr_test_case 38 | ( 39 | "test18" 40 | , L("foobarboo") 41 | , regex_type(L('b') >> +_ >> L("oo") >> eos) 42 | , backrefs(L("barboo"), nilbr) 43 | ) 44 | , xpr_test_case 45 | ( 46 | "test19" 47 | , L("+1234.56789F") 48 | , regex_type(bos >> (s1= !(set=L('-'),L('+')) >> +range(L('0'),L('9')) 49 | >> !(s2= L('.') >> *range(L('0'),L('9')))) 50 | >> (s3= (set=L('C'),L('F'))) >> eos) 51 | , backrefs(L("+1234.56789F"), L("+1234.56789"), L(".56789"), L("F"), nilbr) 52 | ) 53 | , xpr_test_case 54 | ( 55 | "test20" 56 | , L("+1234.56789") 57 | , regex_type( !(s1= as_xpr(L('+'))|L('-')) >> (s2= +range(L('0'),L('9')) >> !as_xpr(L('.')) >> *range(L('0'),L('9')) | 58 | L('.') >> +range(L('0'),L('9'))) >> !(s3= (set=L('e'),L('E')) >> !(s4= as_xpr(L('+'))|L('-')) >> +range(L('0'),L('9')))) 59 | , backrefs(L("+1234.56789"), L("+"), L("1234.56789"), L(""), L(""), nilbr) 60 | ) 61 | }; 62 | 63 | return boost::make_iterator_range(test_cases); 64 | } 65 | 66 | -------------------------------------------------------------------------------- /test/test10u.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test10.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test10.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | #ifndef BOOST_XPRESSIVE_NO_WREGEX 17 | typedef std::wstring::const_iterator iterator_type; 18 | boost::iterator_range const *> rng = get_test_cases(); 19 | std::for_each(rng.begin(), rng.end(), test_runner()); 20 | #endif 21 | } 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // init_unit_test_suite 25 | // 26 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 27 | { 28 | test_suite *test = BOOST_TEST_SUITE("test10u"); 29 | test->add(BOOST_TEST_CASE(&test_main)); 30 | return test; 31 | } 32 | -------------------------------------------------------------------------------- /test/test11.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test11.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test11.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | typedef std::string::const_iterator iterator_type; 17 | boost::iterator_range const *> rng = get_test_cases(); 18 | std::for_each(rng.begin(), rng.end(), test_runner()); 19 | } 20 | 21 | /////////////////////////////////////////////////////////////////////////////// 22 | // init_unit_test_suite 23 | // 24 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 25 | { 26 | test_suite *test = BOOST_TEST_SUITE("test11"); 27 | test->add(BOOST_TEST_CASE(&test_main)); 28 | return test; 29 | } 30 | -------------------------------------------------------------------------------- /test/test11.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test11.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include "./test.hpp" 9 | 10 | /////////////////////////////////////////////////////////////////////////////// 11 | // get_test_cases 12 | // 13 | template 14 | boost::iterator_range const *> get_test_cases() 15 | { 16 | typedef typename boost::iterator_value::type char_type; 17 | typedef xpr_test_case xpr_test_case; 18 | typedef basic_regex regex_type; 19 | 20 | static char_type const *nilbr = 0; 21 | static xpr_test_case const test_cases[] = 22 | { 23 | xpr_test_case 24 | ( 25 | "test166" 26 | , L("G") 27 | , regex_type(L('f') | icase(L('g'))) 28 | , backrefs(L("G"), nilbr) 29 | ) 30 | , xpr_test_case 31 | ( 32 | "test167" 33 | , L("aBBa") 34 | , regex_type(icase(+lower)) 35 | , backrefs(L("aBBa"), nilbr) 36 | ) 37 | , xpr_test_case 38 | ( 39 | "test168" 40 | , L("aA") 41 | , regex_type(icase(+as_xpr(L('\x61')))) 42 | , backrefs(L("aA"), nilbr) 43 | ) 44 | , xpr_test_case 45 | ( 46 | "test169" 47 | , L("aA") 48 | , regex_type(icase(+set[L('\x61')])) 49 | , backrefs(L("aA"), nilbr) 50 | ) 51 | , xpr_test_case 52 | ( 53 | "test170" 54 | , L("aA") 55 | , regex_type(icase(+as_xpr(L('\x0061')))) 56 | , backrefs(L("aA"), nilbr) 57 | ) 58 | , xpr_test_case 59 | ( 60 | "test171" 61 | , L("aA") 62 | , regex_type(icase(+set[L('\x0061')])) 63 | , backrefs(L("aA"), nilbr) 64 | ) 65 | , xpr_test_case 66 | ( 67 | "test172" 68 | , L("abcd") 69 | , regex_type(L('a') >> +(s1= L('b') | (s2= *(s3= L('c')))) >> L('d')) 70 | , backrefs(L("abcd"), L(""), L(""), L(""), nilbr) 71 | ) 72 | , xpr_test_case 73 | ( 74 | "test173" 75 | , L("abcd") 76 | , regex_type(L('a') >> +(s1= L('b') | (s2= !(s3= L('c')))) >> L('d')) 77 | , backrefs(L("abcd"), L(""), L(""), L(""), nilbr) 78 | ) 79 | }; 80 | 81 | return boost::make_iterator_range(test_cases); 82 | } 83 | 84 | -------------------------------------------------------------------------------- /test/test11u.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test11u.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test11.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | #ifndef BOOST_XPRESSIVE_NO_WREGEX 17 | typedef std::wstring::const_iterator iterator_type; 18 | boost::iterator_range const *> rng = get_test_cases(); 19 | std::for_each(rng.begin(), rng.end(), test_runner()); 20 | #endif 21 | } 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // init_unit_test_suite 25 | // 26 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 27 | { 28 | test_suite *test = BOOST_TEST_SUITE("test11u"); 29 | test->add(BOOST_TEST_CASE(&test_main)); 30 | return test; 31 | } 32 | -------------------------------------------------------------------------------- /test/test1u.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test1.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test1.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | #ifndef BOOST_XPRESSIVE_NO_WREGEX 17 | typedef std::wstring::const_iterator iterator_type; 18 | boost::iterator_range const *> rng = get_test_cases(); 19 | std::for_each(rng.begin(), rng.end(), test_runner()); 20 | #endif 21 | } 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // init_unit_test_suite 25 | // 26 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 27 | { 28 | test_suite *test = BOOST_TEST_SUITE("test1u"); 29 | test->add(BOOST_TEST_CASE(&test_main)); 30 | return test; 31 | } 32 | -------------------------------------------------------------------------------- /test/test2.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test2.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test2.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | typedef std::string::const_iterator iterator_type; 17 | boost::iterator_range const *> rng = get_test_cases(); 18 | std::for_each(rng.begin(), rng.end(), test_runner()); 19 | } 20 | 21 | /////////////////////////////////////////////////////////////////////////////// 22 | // init_unit_test_suite 23 | // 24 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 25 | { 26 | test_suite *test = BOOST_TEST_SUITE("test2"); 27 | test->add(BOOST_TEST_CASE(&test_main)); 28 | return test; 29 | } 30 | -------------------------------------------------------------------------------- /test/test2u.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test2.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test2.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | #ifndef BOOST_XPRESSIVE_NO_WREGEX 17 | typedef std::wstring::const_iterator iterator_type; 18 | boost::iterator_range const *> rng = get_test_cases(); 19 | std::for_each(rng.begin(), rng.end(), test_runner()); 20 | #endif 21 | } 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // init_unit_test_suite 25 | // 26 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 27 | { 28 | test_suite *test = BOOST_TEST_SUITE("test2u"); 29 | test->add(BOOST_TEST_CASE(&test_main)); 30 | return test; 31 | } 32 | -------------------------------------------------------------------------------- /test/test3.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test3.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test3.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | typedef std::string::const_iterator iterator_type; 17 | boost::iterator_range const *> rng = get_test_cases(); 18 | std::for_each(rng.begin(), rng.end(), test_runner()); 19 | } 20 | 21 | /////////////////////////////////////////////////////////////////////////////// 22 | // init_unit_test_suite 23 | // 24 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 25 | { 26 | test_suite *test = BOOST_TEST_SUITE("test3"); 27 | test->add(BOOST_TEST_CASE(&test_main)); 28 | return test; 29 | } 30 | -------------------------------------------------------------------------------- /test/test3u.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test3.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test3.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | #ifndef BOOST_XPRESSIVE_NO_WREGEX 17 | typedef std::wstring::const_iterator iterator_type; 18 | boost::iterator_range const *> rng = get_test_cases(); 19 | std::for_each(rng.begin(), rng.end(), test_runner()); 20 | #endif 21 | } 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // init_unit_test_suite 25 | // 26 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 27 | { 28 | test_suite *test = BOOST_TEST_SUITE("test3u"); 29 | test->add(BOOST_TEST_CASE(&test_main)); 30 | return test; 31 | } 32 | -------------------------------------------------------------------------------- /test/test4.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test4.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test4.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | typedef std::string::const_iterator iterator_type; 17 | boost::iterator_range const *> rng = get_test_cases(); 18 | std::for_each(rng.begin(), rng.end(), test_runner()); 19 | } 20 | 21 | /////////////////////////////////////////////////////////////////////////////// 22 | // init_unit_test_suite 23 | // 24 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 25 | { 26 | test_suite *test = BOOST_TEST_SUITE("test4"); 27 | test->add(BOOST_TEST_CASE(&test_main)); 28 | return test; 29 | } 30 | -------------------------------------------------------------------------------- /test/test4u.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test4.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test4.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | #ifndef BOOST_XPRESSIVE_NO_WREGEX 17 | typedef std::wstring::const_iterator iterator_type; 18 | boost::iterator_range const *> rng = get_test_cases(); 19 | std::for_each(rng.begin(), rng.end(), test_runner()); 20 | #endif 21 | } 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // init_unit_test_suite 25 | // 26 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 27 | { 28 | test_suite *test = BOOST_TEST_SUITE("test4u"); 29 | test->add(BOOST_TEST_CASE(&test_main)); 30 | return test; 31 | } 32 | -------------------------------------------------------------------------------- /test/test5.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test5.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test5.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | typedef std::string::const_iterator iterator_type; 17 | boost::iterator_range const *> rng = get_test_cases(); 18 | std::for_each(rng.begin(), rng.end(), test_runner()); 19 | } 20 | 21 | /////////////////////////////////////////////////////////////////////////////// 22 | // init_unit_test_suite 23 | // 24 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 25 | { 26 | test_suite *test = BOOST_TEST_SUITE("test5"); 27 | test->add(BOOST_TEST_CASE(&test_main)); 28 | return test; 29 | } 30 | -------------------------------------------------------------------------------- /test/test5u.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test5.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test5.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | #ifndef BOOST_XPRESSIVE_NO_WREGEX 17 | typedef std::wstring::const_iterator iterator_type; 18 | boost::iterator_range const *> rng = get_test_cases(); 19 | std::for_each(rng.begin(), rng.end(), test_runner()); 20 | #endif 21 | } 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // init_unit_test_suite 25 | // 26 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 27 | { 28 | test_suite *test = BOOST_TEST_SUITE("test5u"); 29 | test->add(BOOST_TEST_CASE(&test_main)); 30 | return test; 31 | } 32 | -------------------------------------------------------------------------------- /test/test6.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test6.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test6.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | typedef std::string::const_iterator iterator_type; 17 | boost::iterator_range const *> rng = get_test_cases(); 18 | std::for_each(rng.begin(), rng.end(), test_runner()); 19 | } 20 | 21 | /////////////////////////////////////////////////////////////////////////////// 22 | // init_unit_test_suite 23 | // 24 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 25 | { 26 | test_suite *test = BOOST_TEST_SUITE("test6"); 27 | test->add(BOOST_TEST_CASE(&test_main)); 28 | return test; 29 | } 30 | -------------------------------------------------------------------------------- /test/test6u.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test6.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test6.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | #ifndef BOOST_XPRESSIVE_NO_WREGEX 17 | typedef std::wstring::const_iterator iterator_type; 18 | boost::iterator_range const *> rng = get_test_cases(); 19 | std::for_each(rng.begin(), rng.end(), test_runner()); 20 | #endif 21 | } 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // init_unit_test_suite 25 | // 26 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 27 | { 28 | test_suite *test = BOOST_TEST_SUITE("test6u"); 29 | test->add(BOOST_TEST_CASE(&test_main)); 30 | return test; 31 | } 32 | -------------------------------------------------------------------------------- /test/test7.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test7.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test7.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | typedef std::string::const_iterator iterator_type; 17 | boost::iterator_range const *> rng = get_test_cases(); 18 | std::for_each(rng.begin(), rng.end(), test_runner()); 19 | } 20 | 21 | /////////////////////////////////////////////////////////////////////////////// 22 | // init_unit_test_suite 23 | // 24 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 25 | { 26 | test_suite *test = BOOST_TEST_SUITE("test7"); 27 | test->add(BOOST_TEST_CASE(&test_main)); 28 | return test; 29 | } 30 | -------------------------------------------------------------------------------- /test/test7u.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test7.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test7.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | #ifndef BOOST_XPRESSIVE_NO_WREGEX 17 | typedef std::wstring::const_iterator iterator_type; 18 | boost::iterator_range const *> rng = get_test_cases(); 19 | std::for_each(rng.begin(), rng.end(), test_runner()); 20 | #endif 21 | } 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // init_unit_test_suite 25 | // 26 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 27 | { 28 | test_suite *test = BOOST_TEST_SUITE("test7u"); 29 | test->add(BOOST_TEST_CASE(&test_main)); 30 | return test; 31 | } 32 | -------------------------------------------------------------------------------- /test/test8.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test8.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test8.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | typedef std::string::const_iterator iterator_type; 17 | boost::iterator_range const *> rng = get_test_cases(); 18 | std::for_each(rng.begin(), rng.end(), test_runner()); 19 | } 20 | 21 | /////////////////////////////////////////////////////////////////////////////// 22 | // init_unit_test_suite 23 | // 24 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 25 | { 26 | test_suite *test = BOOST_TEST_SUITE("test8"); 27 | test->add(BOOST_TEST_CASE(&test_main)); 28 | return test; 29 | } 30 | -------------------------------------------------------------------------------- /test/test8.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test8.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include "./test.hpp" 9 | 10 | /////////////////////////////////////////////////////////////////////////////// 11 | // get_test_cases 12 | // 13 | template 14 | boost::iterator_range const *> get_test_cases() 15 | { 16 | typedef typename boost::iterator_value::type char_type; 17 | typedef xpr_test_case xpr_test_case; 18 | typedef basic_regex regex_type; 19 | 20 | static char_type const *nilbr = 0; 21 | static xpr_test_case const test_cases[] = 22 | { 23 | xpr_test_case 24 | ( 25 | "test141" 26 | , L("bbbc") 27 | , regex_type(bos >> repeat<2>(s1= optional(L('b'))) >> L("bc") >> eos) 28 | , backrefs(L("bbbc"), L("b"), nilbr) 29 | ) 30 | , xpr_test_case 31 | ( 32 | "test142" 33 | , L("bbbbc") 34 | , regex_type(bos >> repeat<2>(s1= optional(L('b'))) >> L("bc") >> eos) 35 | , no_match 36 | ) 37 | , xpr_test_case 38 | ( 39 | "test143" 40 | , L("bbbbc") 41 | , regex_type(bos >> *(s1= optional(L('b'))) >> L('d') >> eos) 42 | , no_match 43 | ) 44 | , xpr_test_case 45 | ( 46 | "test144" 47 | , L("bc") 48 | , regex_type(bos >> -repeat<2>(s1= optional(L('b'))) >> L("bc") >> eos) 49 | , backrefs(L("bc"), L(""), nilbr) 50 | ) 51 | , xpr_test_case 52 | ( 53 | "test145" 54 | , L("bbc") 55 | , regex_type(bos >> -repeat<2>(s1= optional(L('b'))) >> L("bc") >> eos) 56 | , backrefs(L("bbc"), L(""), nilbr) 57 | ) 58 | , xpr_test_case 59 | ( 60 | "test146" 61 | , L("bbbc") 62 | , regex_type(bos >> -repeat<2>(s1= optional(L('b'))) >> L("bc") >> eos) 63 | , backrefs(L("bbbc"), L("b"), nilbr) 64 | ) 65 | , xpr_test_case 66 | ( 67 | "test147" 68 | , L("bbbbc") 69 | , regex_type(bos >> -repeat<2>(s1= optional(L('b'))) >> L("bc") >> eos) 70 | , no_match 71 | ) 72 | , xpr_test_case 73 | ( 74 | "test148" 75 | , L("bbbbc") 76 | , regex_type(bos >> -*(s1= optional(L('b'))) >> L('d') >> eos) 77 | , no_match 78 | ) 79 | , xpr_test_case 80 | ( 81 | "test149" 82 | , L("bc") 83 | , regex_type(bos >> repeat<2>(s1= -optional(L('b'))) >> L("bc") >> eos) 84 | , backrefs(L("bc"), L(""), nilbr) 85 | ) 86 | , xpr_test_case 87 | ( 88 | "test150" 89 | , L("bbc") 90 | , regex_type(bos >> repeat<2>(s1= -optional(L('b'))) >> L("bc") >> eos) 91 | , backrefs(L("bbc"), L("b"), nilbr) 92 | ) 93 | }; 94 | 95 | return boost::make_iterator_range(test_cases); 96 | } 97 | -------------------------------------------------------------------------------- /test/test8u.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test8.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test8.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | #ifndef BOOST_XPRESSIVE_NO_WREGEX 17 | typedef std::wstring::const_iterator iterator_type; 18 | boost::iterator_range const *> rng = get_test_cases(); 19 | std::for_each(rng.begin(), rng.end(), test_runner()); 20 | #endif 21 | } 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // init_unit_test_suite 25 | // 26 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 27 | { 28 | test_suite *test = BOOST_TEST_SUITE("test8u"); 29 | test->add(BOOST_TEST_CASE(&test_main)); 30 | return test; 31 | } 32 | -------------------------------------------------------------------------------- /test/test9.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test9.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test9.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | typedef std::string::const_iterator iterator_type; 17 | boost::iterator_range const *> rng = get_test_cases(); 18 | std::for_each(rng.begin(), rng.end(), test_runner()); 19 | } 20 | 21 | /////////////////////////////////////////////////////////////////////////////// 22 | // init_unit_test_suite 23 | // 24 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 25 | { 26 | test_suite *test = BOOST_TEST_SUITE("test9"); 27 | test->add(BOOST_TEST_CASE(&test_main)); 28 | return test; 29 | } 30 | -------------------------------------------------------------------------------- /test/test9u.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test9.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./test9.hpp" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | // read the tests from the input file and execute them 14 | void test_main() 15 | { 16 | #ifndef BOOST_XPRESSIVE_NO_WREGEX 17 | typedef std::wstring::const_iterator iterator_type; 18 | boost::iterator_range const *> rng = get_test_cases(); 19 | std::for_each(rng.begin(), rng.end(), test_runner()); 20 | #endif 21 | } 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | // init_unit_test_suite 25 | // 26 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 27 | { 28 | test_suite *test = BOOST_TEST_SUITE("test9u"); 29 | test->add(BOOST_TEST_CASE(&test_main)); 30 | return test; 31 | } 32 | -------------------------------------------------------------------------------- /test/test_assert.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test_assert.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace boost::xpressive; 14 | 15 | bool three_or_six(ssub_match const &sub) 16 | { 17 | return sub.length() == 3 || sub.length() == 6; 18 | } 19 | 20 | /////////////////////////////////////////////////////////////////////////////// 21 | // test1 22 | // simple custom assert that checks the length of a matched sub-expression 23 | void test1() 24 | { 25 | std::string str("foo barbaz fink"); 26 | // match words of 3 characters or 6 characters. 27 | sregex rx = (bow >> +_w >> eow)[ check(&three_or_six) ] ; 28 | 29 | sregex_iterator first(str.begin(), str.end(), rx), last; 30 | BOOST_CHECK_EQUAL(std::distance(first, last), 2); 31 | } 32 | 33 | /////////////////////////////////////////////////////////////////////////////// 34 | // test2 35 | // same as above, but using a lambda 36 | void test2() 37 | { 38 | std::string str("foo barbaz fink"); 39 | // match words of 3 characters or 6 characters. 40 | sregex rx = (bow >> +_w >> eow)[ check(length(_)==3 || length(_)==6) ] ; 41 | 42 | sregex_iterator first(str.begin(), str.end(), rx), last; 43 | BOOST_CHECK_EQUAL(std::distance(first, last), 2); 44 | } 45 | 46 | /////////////////////////////////////////////////////////////////////////////// 47 | // test3 48 | // more complicated use of custom assertions to validate a date 49 | void test3() 50 | { 51 | int const days_per_month[] = 52 | {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 31, 31}; 53 | 54 | mark_tag month(1), day(2); 55 | // find a valid date of the form month/day/year. 56 | sregex date = 57 | ( 58 | // Month must be between 1 and 12 inclusive 59 | (month= _d >> !_d) [ check(as(_) >= 1 60 | && as(_) <= 12) ] 61 | >> '/' 62 | // Day must be between 1 and 31 inclusive 63 | >> (day= _d >> !_d) [ check(as(_) >= 1 64 | && as(_) <= 31) ] 65 | >> '/' 66 | // Only consider years between 1970 and 2038 67 | >> (_d >> _d >> _d >> _d) [ check(as(_) >= 1970 68 | && as(_) <= 2038) ] 69 | ) 70 | // Ensure the month actually has that many days. 71 | [ check( ref(days_per_month)[as(month)-1] >= as(day) ) ] 72 | ; 73 | 74 | smatch what; 75 | std::string str("99/99/9999 2/30/2006 2/28/2006"); 76 | 77 | BOOST_REQUIRE(regex_search(str, what, date)); 78 | BOOST_CHECK_EQUAL(what[0], "2/28/2006"); 79 | } 80 | 81 | using namespace boost::unit_test; 82 | 83 | /////////////////////////////////////////////////////////////////////////////// 84 | // init_unit_test_suite 85 | // 86 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 87 | { 88 | test_suite *test = BOOST_TEST_SUITE("test_assert"); 89 | test->add(BOOST_TEST_CASE(&test1)); 90 | test->add(BOOST_TEST_CASE(&test2)); 91 | test->add(BOOST_TEST_CASE(&test3)); 92 | return test; 93 | } 94 | 95 | -------------------------------------------------------------------------------- /test/test_assert_with_placeholder.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test_assert_with_placeholder.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | using namespace boost::xpressive; 13 | 14 | placeholder const _cnt = {{}}; 15 | 16 | struct count_a_impl 17 | { 18 | typedef void result_type; 19 | 20 | void operator()(int &cnt) const 21 | { 22 | ++cnt; 23 | } 24 | }; 25 | 26 | boost::xpressive::function::type const count_a = {{}}; 27 | 28 | struct check_a_impl 29 | { 30 | typedef bool result_type; 31 | 32 | bool operator()(int &cnt, int val) const 33 | { 34 | if(cnt < val) 35 | { 36 | ++cnt; 37 | return true; 38 | } 39 | return false; 40 | } 41 | }; 42 | 43 | boost::xpressive::function::type const check_a = {{}}; 44 | 45 | void test_assert_with_placeholder() 46 | { 47 | int cnt = 0; 48 | std::string a_str("a_aaaaa___a_aa_aaa_"); 49 | const sregex expr1(*(as_xpr('a')[count_a(_cnt)] | '_')); 50 | const sregex expr2(*(as_xpr('a')[check(check_a(_cnt, 5))] | '_')); 51 | 52 | sregex_iterator iter1(a_str.begin(), a_str.end(), expr1, 53 | let(_cnt = cnt)); 54 | BOOST_CHECK_EQUAL(iter1->str(0), a_str); 55 | BOOST_CHECK_EQUAL(cnt, 12); 56 | 57 | cnt = 0; 58 | sregex_iterator iter2(a_str.begin(), a_str.end(), expr2, 59 | let(_cnt = cnt)); 60 | 61 | BOOST_CHECK_EQUAL(iter2->str(0), std::string("a_aaaa")); 62 | BOOST_CHECK_EQUAL(cnt, 5); 63 | } 64 | 65 | using namespace boost::unit_test; 66 | /////////////////////////////////////////////////////////////////////////////// 67 | // init_unit_test_suite 68 | // 69 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 70 | { 71 | test_suite *test = BOOST_TEST_SUITE("test that custom assertions can use argument placeholders"); 72 | 73 | test->add(BOOST_TEST_CASE(&test_assert_with_placeholder)); 74 | 75 | return test; 76 | } 77 | -------------------------------------------------------------------------------- /test/test_basic_regex.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test_basic_regex.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | 10 | -------------------------------------------------------------------------------- /test/test_dynamic.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test_dynamic.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | void test_main() 14 | { 15 | using namespace boost::xpressive; 16 | 17 | std::string str("bar"); 18 | sregex rx = sregex::compile("b.*ar"); 19 | smatch what; 20 | 21 | if(!regex_match(str, what, rx)) 22 | { 23 | BOOST_ERROR("oops"); 24 | } 25 | } 26 | 27 | using namespace boost::unit_test; 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // init_unit_test_suite 31 | // 32 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 33 | { 34 | test_suite *test = BOOST_TEST_SUITE("test_dynamic"); 35 | test->add(BOOST_TEST_CASE(&test_main)); 36 | return test; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /test/test_match_results.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test_match_results.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | 10 | -------------------------------------------------------------------------------- /test/test_non_char.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test_non_char.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include 11 | #include "./test.hpp" 12 | 13 | /////////////////////////////////////////////////////////////////////////////// 14 | // test_static 15 | void test_static() 16 | { 17 | static int const data[] = {0, 1, 2, 3, 4, 5, 6}; 18 | null_regex_traits nul; 19 | basic_regex rex = imbue(nul)(1 >> +((set= 2,3) | 4) >> 5); 20 | match_results what; 21 | 22 | if(!regex_search(data, data + (sizeof(data)/sizeof(*data)), what, rex)) 23 | { 24 | BOOST_ERROR("regex_search on integral data failed"); 25 | } 26 | else 27 | { 28 | BOOST_CHECK(*what[0].first == 1); 29 | BOOST_CHECK(*what[0].second == 6); 30 | } 31 | } 32 | 33 | /////////////////////////////////////////////////////////////////////////////// 34 | // UChar 35 | struct UChar 36 | { 37 | UChar(unsigned int code = 0) 38 | : code_(code) 39 | {} 40 | 41 | operator unsigned int () const 42 | { 43 | return this->code_; 44 | } 45 | 46 | private: 47 | unsigned int code_; 48 | }; 49 | 50 | /////////////////////////////////////////////////////////////////////////////// 51 | // UChar_traits 52 | struct UChar_traits 53 | : null_regex_traits 54 | {}; 55 | 56 | /////////////////////////////////////////////////////////////////////////////// 57 | // test_dynamic 58 | void test_dynamic() 59 | { 60 | typedef std::vector::const_iterator uchar_iterator; 61 | typedef basic_regex uregex; 62 | typedef match_results umatch; 63 | typedef regex_compiler uregex_compiler; 64 | 65 | std::string pattern_("b.*r"), str_("foobarboo"); 66 | std::vector pattern(pattern_.begin(), pattern_.end()); 67 | std::vector str(str_.begin(), str_.end()); 68 | 69 | UChar_traits tr; 70 | uregex_compiler compiler(tr); 71 | uregex urx = compiler.compile(pattern); 72 | umatch what; 73 | 74 | if(!regex_search(str, what, urx)) 75 | { 76 | BOOST_ERROR("regex_search on UChar failed"); 77 | } 78 | else 79 | { 80 | BOOST_CHECK_EQUAL(3, what.position()); 81 | BOOST_CHECK_EQUAL(3, what.length()); 82 | } 83 | 84 | // test for range-based regex_replace 85 | std::vector output = regex_replace(str, urx, pattern_); 86 | std::string output_(output.begin(), output.end()); 87 | std::string expected("foob.*rboo"); 88 | BOOST_CHECK_EQUAL(output_, expected); 89 | } 90 | 91 | /////////////////////////////////////////////////////////////////////////////// 92 | // init_unit_test_suite 93 | // 94 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 95 | { 96 | test_suite *test = BOOST_TEST_SUITE("test_non_char"); 97 | test->add(BOOST_TEST_CASE(&test_static)); 98 | test->add(BOOST_TEST_CASE(&test_dynamic)); 99 | return test; 100 | } 101 | 102 | -------------------------------------------------------------------------------- /test/test_partial_match.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test_partial_match.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include "./test.hpp" 9 | 10 | /////////////////////////////////////////////////////////////////////////////// 11 | // test_main 12 | // read the tests from the input file and execute them 13 | void test_main() 14 | { 15 | 16 | 17 | 18 | 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /test/test_regex_algorithms.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test_regex_algorithms.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | 10 | -------------------------------------------------------------------------------- /test/test_regex_compiler.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test_regex_compiler.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | 10 | -------------------------------------------------------------------------------- /test/test_regex_constants.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test_regex_constants.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | 10 | -------------------------------------------------------------------------------- /test/test_regex_error.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test_regex_error.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | 10 | -------------------------------------------------------------------------------- /test/test_regex_iterator.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test_regex_iterator.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | 10 | -------------------------------------------------------------------------------- /test/test_regex_primitives.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test_regex_primitives.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | 10 | -------------------------------------------------------------------------------- /test/test_regex_token_iterator.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test_regex_token_iterator.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | 10 | -------------------------------------------------------------------------------- /test/test_regex_traits.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test_regex_traits.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | 10 | -------------------------------------------------------------------------------- /test/test_skip.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test_skip.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace boost::unit_test; 15 | using namespace boost::xpressive; 16 | 17 | void test1() 18 | { 19 | std::string s = "a a b b c c"; 20 | 21 | sregex rx = 22 | "a a" >> 23 | skip(_s) 24 | ( 25 | (s1= as_xpr('b')) >> 26 | as_xpr('b') >> 27 | *as_xpr('c') // causes backtracking 28 | ) >> 29 | "c c"; 30 | 31 | smatch what; 32 | BOOST_CHECK( regex_match(s, what, rx) ); 33 | 34 | s = "123,456,789"; 35 | sregex rx2 = skip(',')(+_d); 36 | BOOST_CHECK( regex_match(s, what, rx2) ); 37 | 38 | s = "foo"; 39 | sregex rx3 = skip(_s)(after("fo") >> 'o'); 40 | BOOST_CHECK( regex_search(s, what, rx3) ); 41 | } 42 | 43 | template 44 | void test_skip_aux(Expr const &expr) 45 | { 46 | sregex rx = skip(_s)(expr); 47 | } 48 | 49 | void test_skip() 50 | { 51 | int i=0; 52 | std::map syms; 53 | std::locale loc; 54 | 55 | test_skip_aux( 'a' ); 56 | test_skip_aux( _ ); 57 | test_skip_aux( +_ ); 58 | test_skip_aux( -+_ ); 59 | test_skip_aux( !_ ); 60 | test_skip_aux( -!_ ); 61 | test_skip_aux( repeat<0,42>(_) ); 62 | test_skip_aux( -repeat<0,42>(_) ); 63 | test_skip_aux( _ >> 'a' ); 64 | test_skip_aux( _ >> 'a' | _ ); 65 | test_skip_aux( _ >> 'a' | _ >> 'b' ); 66 | test_skip_aux( s1= _ >> 'a' | _ >> 'b' ); 67 | test_skip_aux( icase(_ >> 'a' | _ >> 'b') ); 68 | test_skip_aux( imbue(loc)(_ >> 'a' | _ >> 'b') ); 69 | test_skip_aux( (set='a') ); 70 | test_skip_aux( (set='a','b') ); 71 | test_skip_aux( ~(set='a') ); 72 | test_skip_aux( ~(set='a','b') ); 73 | test_skip_aux( range('a','b') ); 74 | test_skip_aux( ~range('a','b') ); 75 | test_skip_aux( set['a' | alpha] ); 76 | test_skip_aux( ~set['a' | alpha] ); 77 | test_skip_aux( before(_) ); 78 | test_skip_aux( ~before(_) ); 79 | test_skip_aux( after(_) ); 80 | test_skip_aux( ~after(_) ); 81 | test_skip_aux( keep(*_) ); 82 | test_skip_aux( (*_)[ref(i) = as(_) + 1] ); 83 | test_skip_aux( (a1= syms)[ref(i) = a1 + 1] ); 84 | } 85 | 86 | /////////////////////////////////////////////////////////////////////////////// 87 | // init_unit_test_suite 88 | // 89 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 90 | { 91 | test_suite *test = BOOST_TEST_SUITE("test skip()"); 92 | 93 | test->add(BOOST_TEST_CASE(&test1)); 94 | 95 | return test; 96 | } 97 | -------------------------------------------------------------------------------- /test/test_static.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test_static.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // test_main 13 | void test_main() 14 | { 15 | using namespace boost::xpressive; 16 | 17 | std::string str("bar"); 18 | sregex rx = 'b' >> *_ >> "ar"; 19 | smatch what; 20 | 21 | if(!regex_match(str, what, rx)) 22 | { 23 | BOOST_ERROR("oops"); 24 | } 25 | } 26 | 27 | using namespace boost::unit_test; 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // init_unit_test_suite 31 | // 32 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 33 | { 34 | test_suite *test = BOOST_TEST_SUITE("test_static"); 35 | test->add(BOOST_TEST_CASE(&test_main)); 36 | return test; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /test/test_sub_match.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // test_sub_match.cpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | 10 | -------------------------------------------------------------------------------- /tools/Jamfile.v2: -------------------------------------------------------------------------------- 1 | # (C) Copyright 2004: Eric Niebler 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | 5 | project 6 | : requirements 7 | /boost/xpressive//boost_xpressive 8 | intel:off 9 | msvc-7.1:off 10 | msvc-8.0:_SCL_SECURE_NO_DEPRECATE 11 | msvc-8.0:_CRT_SECURE_NO_DEPRECATE 12 | msvc-9.0:_SCL_SECURE_NO_DEPRECATE 13 | gcc:-ftemplate-depth-1024 14 | msvc,stlport:_STLP_EXPOSE_GLOBALS_IMPLEMENTATION 15 | ; 16 | 17 | exe perl2xpr 18 | : 19 | perl2xpr.cpp 20 | ; 21 | --------------------------------------------------------------------------------