1 /*=============================================================================
2 Boost.Wave: A Standard compliant C++ preprocessor library
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 =============================================================================*/
10 // disable stupid compiler warnings
11 #include <boost/config/warning_disable.hpp>
14 #if defined(TESTLEXERS_TIMING)
20 #include <boost/wave/wave_config.hpp>
21 #if !BOOST_WORKAROUND(__SUNPRO_CC, <= 0x580)
22 #undef BOOST_WAVE_SEPARATE_LEXER_INSTANTIATION
25 #include <boost/detail/lightweight_test.hpp>
26 #if defined(TESTLEXERS_TIMING)
27 #include "high_resolution_timer.hpp"
30 // include the Re2C lexer related stuff
31 #include <boost/wave/cpplexer/cpp_lex_token.hpp> // token type
32 #include <boost/wave/cpplexer/cpp_lex_iterator.hpp>
33 #include <boost/wave/cpplexer/re2clex/cpp_re2c_lexer.hpp> // lexer type
35 typedef boost::wave::cpplexer::lex_token
<> token_type
;
36 typedef boost::wave::cpplexer::lex_iterator
<token_type
> lexer_type
;
38 ///////////////////////////////////////////////////////////////////////////////
40 #include "cpp_tokens.hpp"
42 ///////////////////////////////////////////////////////////////////////////////
44 main(int argc
, char *argv
[])
47 token_type::position_type
pos("<testdata>");
49 #if defined(TESTLEXERS_TIMING)
50 boost::high_resolution_timer tim
;
51 for (int i
= 0; i
< 1000; ++i
) {
54 for (lexem
const* data
= lexems
; NULL
!= data
->token
; ++data
) {
55 // feed the token to the lexer
56 token_type::string_type
instr(data
->token
);
58 lexer_type it
= lexer_type(instr
.begin(), instr
.end(), pos
,
59 boost::wave::support_cpp2a
);
60 lexer_type end
= lexer_type();
62 // verify the correct outcome of the tokenization
63 #if defined(TESTLEXERS_VERBOSE)
64 std::cerr
<< boost::wave::get_token_name(data
->id
) << std::endl
;
67 if (data
->id
!= boost::wave::token_id(*it
)) {
68 BOOST_TEST(data
->id
== boost::wave::token_id(*it
));
69 std::cerr
<< data
->token
<< ": expected: "
70 << boost::wave::get_token_name(data
->id
);
71 std::cerr
<< ", found: "
72 << boost::wave::get_token_name(boost::wave::token_id(*it
))
75 BOOST_TEST(++it
!= end
);
76 if (boost::wave::T_EOF
!= boost::wave::token_id(*it
)) {
77 BOOST_TEST(boost::wave::T_EOF
== boost::wave::token_id(*it
));
78 std::cerr
<< data
->token
<< ": not fully matched, "
79 << "first non-matched token was: " << (*it
).get_value()
84 #if defined(TESTLEXERS_TIMING)
86 std::cout
<< tim
.elapsed() << " [s]" << std::endl
;
89 catch (boost::wave::cpplexer::lexing_exception
&e
) {
92 << "test_re2c_lexer: "
93 << e
.description() << std::endl
;
94 return (std::numeric_limits
<int>::max
)() - 1;
97 return boost::report_errors();