]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/wave/test/testlexers/test_re2c_lexer.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / wave / test / testlexers / test_re2c_lexer.cpp
1 /*=============================================================================
2 Boost.Wave: A Standard compliant C++ preprocessor library
3 http://www.boost.org/
4
5 Copyright (c) 2001-2012 Hartmut Kaiser. 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
10 // disable stupid compiler warnings
11 #include <boost/config/warning_disable.hpp>
12
13 // system headers
14 #include <string>
15 #include <iostream>
16 #include <limits>
17
18 #include <boost/wave/wave_config.hpp>
19 #if !BOOST_WORKAROUND(__SUNPRO_CC, <= 0x580)
20 #undef BOOST_WAVE_SEPARATE_LEXER_INSTANTIATION
21 #endif
22
23 #include <boost/detail/lightweight_test.hpp>
24 #if defined(TESTLEXERS_TIMING)
25 #include "high_resolution_timer.hpp"
26 #endif
27
28 // include the Re2C lexer related stuff
29 #include <boost/wave/cpplexer/cpp_lex_token.hpp> // token type
30 #include <boost/wave/cpplexer/cpp_lex_iterator.hpp>
31 #include <boost/wave/cpplexer/re2clex/cpp_re2c_lexer.hpp> // lexer type
32
33 typedef boost::wave::cpplexer::lex_token<> token_type;
34 typedef boost::wave::cpplexer::lex_iterator<token_type> lexer_type;
35
36 ///////////////////////////////////////////////////////////////////////////////
37 // include test data
38 #include "cpp_tokens.hpp"
39
40 ///////////////////////////////////////////////////////////////////////////////
41 int
42 main(int argc, char *argv[])
43 {
44 try {
45 token_type::position_type pos("<testdata>");
46
47 #if defined(TESTLEXERS_TIMING)
48 boost::high_resolution_timer tim;
49 for (int i = 0; i < 1000; ++i) {
50 #endif
51
52 for (lexem const* data = lexems; NULL != data->token; ++data) {
53 // feed the token to the lexer
54 token_type::string_type instr(data->token);
55
56 lexer_type it = lexer_type(instr.begin(), instr.end(), pos,
57 boost::wave::support_option_long_long);
58 lexer_type end = lexer_type();
59
60 // verify the correct outcome of the tokenization
61 #if defined(TESTLEXERS_VERBOSE)
62 std::cerr << boost::wave::get_token_name(data->id) << std::endl;
63 #endif
64
65 if (data->id != boost::wave::token_id(*it)) {
66 BOOST_TEST(data->id == boost::wave::token_id(*it));
67 std::cerr << data->token << ": expected: "
68 << boost::wave::get_token_name(data->id);
69 std::cerr << ", found: "
70 << boost::wave::get_token_name(boost::wave::token_id(*it))
71 << std::endl;
72 }
73 BOOST_TEST(++it != end);
74 if (boost::wave::T_EOF != boost::wave::token_id(*it)) {
75 BOOST_TEST(boost::wave::T_EOF == boost::wave::token_id(*it));
76 std::cerr << data->token << ": not fully matched, "
77 << "first non-matched token was: " << (*it).get_value()
78 << std::endl;
79 }
80 }
81
82 #if defined(TESTLEXERS_TIMING)
83 }
84 std::cout << tim.elapsed() << " [s]" << std::endl;
85 #endif
86 }
87 catch (boost::wave::cpplexer::lexing_exception &e) {
88 // some lexing error
89 std::cerr
90 << "test_re2c_lexer: "
91 << e.description() << std::endl;
92 return (std::numeric_limits<int>::max)() - 1;
93 }
94
95 return boost::report_errors();
96 }
97