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>
15 #if defined(TESTLEXERS_TIMING)
20 #include <boost/wave/wave_config.hpp>
21 #undef BOOST_WAVE_SEPARATE_LEXER_INSTANTIATION
23 #include <boost/detail/lightweight_test.hpp>
24 #if defined(TESTLEXERS_TIMING)
25 #include "high_resolution_timer.hpp"
28 ///////////////////////////////////////////////////////////////////////////////
29 // include the Slex lexer related stuff
30 #include <libs/wave/samples/cpp_tokens/slex_token.hpp> // token type
31 #include <libs/wave/samples/cpp_tokens/slex/cpp_slex_lexer.hpp> // lexer type
33 typedef boost::wave::cpplexer::slex_token
<> token_type
;
34 typedef boost::wave::cpplexer::slex::slex_iterator
<token_type
> lexer_type
;
36 // This instantiates the correct 'new_lexer' function, which generates the
37 // C++ lexer used in this test.
38 template struct boost::wave::cpplexer::slex::new_lexer_gen
<
39 std::string::iterator
>;
41 ///////////////////////////////////////////////////////////////////////////////
43 #include "cpp_tokens.hpp"
45 ///////////////////////////////////////////////////////////////////////////////
47 main(int argc
, char *argv
[])
50 token_type::position_type
pos("<testdata>");
52 #if defined(TESTLEXERS_TIMING)
53 boost::high_resolution_timer tim
;
54 for (int i
= 0; i
< 1000; ++i
) {
57 for (lexem
const* data
= lexems
; NULL
!= data
->token
; ++data
) {
58 // feed the token to the lexer
59 token_type::string_type
instr(data
->token
);
61 lexer_type it
= lexer_type(instr
.begin(), instr
.end(), pos
,
62 boost::wave::support_cpp2a
);
63 lexer_type end
= lexer_type();
65 // verify the correct outcome of the tokenization
66 #if defined(TESTLEXERS_VERBOSE)
67 std::cerr
<< boost::wave::get_token_name(data
->id
) << std::endl
;
70 if (data
->id
!= boost::wave::token_id(*it
)) {
71 BOOST_TEST(data
->id
== boost::wave::token_id(*it
));
72 std::cerr
<< data
->token
<< ": expected: "
73 << boost::wave::get_token_name(data
->id
);
74 std::cerr
<< ", found: "
75 << boost::wave::get_token_name(boost::wave::token_id(*it
))
78 BOOST_TEST(++it
!= end
);
79 if (boost::wave::T_EOF
!= boost::wave::token_id(*it
)) {
80 BOOST_TEST(boost::wave::T_EOF
== boost::wave::token_id(*it
));
81 std::cerr
<< data
->token
<< ": not fully matched, "
82 << "first non-matched token was: " << (*it
).get_value()
87 #if defined(TESTLEXERS_TIMING)
89 std::cout
<< tim
.elapsed() << " [s]" << std::endl
;
92 catch (boost::wave::cpplexer::lexing_exception
&e
) {
95 << "test_slex_lexer: "
96 << e
.description() << std::endl
;
97 return (std::numeric_limits
<int>::max
)() - 1;
100 return boost::report_errors();