Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/xpressive/test/misc2.cpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 1.5 KB
Line 
1///////////////////////////////////////////////////////////////////////////////
2// misc2.hpp
3//
4//  Copyright 2004 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 <iostream>
9#include <boost/xpressive/xpressive.hpp>
10#include <boost/xpressive/traits/cpp_regex_traits.hpp>
11#include "./test_minimal.hpp"
12
13using namespace boost::xpressive;
14
15///////////////////////////////////////////////////////////////////////////////
16// test for a sub-match scoping
17//
18void test5()
19{
20    sregex inner = sregex::compile( "(.)\\1" );
21    sregex outer = (s1= _) >> inner >> s1;
22    std::string abba("ABBA");
23
24    BOOST_CHECK(regex_match(abba, outer));
25}
26
27///////////////////////////////////////////////////////////////////////////////
28// Ye olde calculator. Test recursive grammar.
29//
30void test6()
31{
32    sregex group, factor, term, expression;
33
34    group       = '(' >> by_ref(expression) >> ')';
35    factor      = +_d | group;
36    term        = factor >> *(('*' >> factor) | ('/' >> factor));
37    expression  = term >> *(('+' >> term) | ('-' >> term));
38
39    smatch what;
40    std::string str("foo 9*(10+3) bar");
41
42    BOOST_REQUIRE(regex_search(str, what, expression));
43    BOOST_CHECK("9*(10+3)" == what[0]);
44}
45
46///////////////////////////////////////////////////////////////////////////////
47// test_main
48//
49int test_main( int, char*[] )
50{
51    test5();
52    test6();
53
54    return 0;
55}
Note: See TracBrowser for help on using the repository browser.