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 =============================================================================*/
13 #if defined(TESTLEXERS_TIMING)
17 #include <boost/wave/wave_config.hpp>
18 #undef BOOST_WAVE_SEPARATE_LEXER_INSTANTIATION
20 #include <boost/detail/lightweight_test.hpp>
21 #if defined(TESTLEXERS_TIMING)
22 #include "high_resolution_timer.hpp"
25 // include the lexertl lexer related stuff
26 #include <boost/wave/cpplexer/cpp_lex_token.hpp> // token type
27 #include <libs/wave/samples/list_includes/lexertl/lexertl_lexer.hpp> // lexer type
29 typedef boost::wave::cpplexer::lex_token
<> token_type
;
30 typedef boost::wave::cpplexer::lexertl::lex_iterator
<token_type
> lexer_type
;
32 ///////////////////////////////////////////////////////////////////////////////
34 #include "cpp_tokens.hpp"
36 ///////////////////////////////////////////////////////////////////////////////
38 main(int argc
, char *argv
[])
41 token_type::position_type
pos("<testdata>");
43 #if defined(TESTLEXERS_TIMING)
44 boost::high_resolution_timer tim
;
45 for (int i
= 0; i
< 1000; ++i
) {
48 for (lexem
const* data
= lexems
; NULL
!= data
->token
; ++data
) {
49 // feed the token to the lexer
50 token_type::string_type
instr(data
->token
);
52 lexer_type it
= lexer_type(instr
.begin(), instr
.end(), pos
,
53 boost::wave::support_cpp2a
);
54 lexer_type end
= lexer_type();
56 // verify the correct outcome of the tokenization
57 #if defined(TESTLEXERS_VERBOSE)
58 std::cerr
<< boost::wave::get_token_name(data
->id
) << std::endl
;
61 if (data
->id
!= boost::wave::token_id(*it
)) {
62 BOOST_TEST(data
->id
== boost::wave::token_id(*it
));
63 std::cerr
<< data
->token
<< ": expected: "
64 << boost::wave::get_token_name(data
->id
);
65 std::cerr
<< ", found: "
66 << boost::wave::get_token_name(boost::wave::token_id(*it
))
69 BOOST_TEST(++it
!= end
);
70 if (boost::wave::T_EOF
!= boost::wave::token_id(*it
)) {
71 BOOST_TEST(boost::wave::T_EOF
== boost::wave::token_id(*it
));
72 std::cerr
<< data
->token
<< ": not fully matched, "
73 << "first non-matched token was: " << (*it
).get_value()
78 #if defined(TESTLEXERS_TIMING)
80 std::cout
<< tim
.elapsed() << " [s]" << std::endl
;
83 catch (boost::wave::cpplexer::lexing_exception
&e
) {
86 << "test_lexertl_lexer: "
87 << e
.description() << std::endl
;
88 return (std::numeric_limits
<int>::max
)() - 1;
91 return boost::report_errors();