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>
18 #include <boost/wave/wave_config.hpp>
19 #if !BOOST_WORKAROUND(__SUNPRO_CC, <= 0x580)
20 #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 // 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
33 typedef boost::wave::cpplexer::lex_token
<> token_type
;
34 typedef boost::wave::cpplexer::lex_iterator
<token_type
> lexer_type
;
36 ///////////////////////////////////////////////////////////////////////////////
38 #include "cpp_tokens.hpp"
40 ///////////////////////////////////////////////////////////////////////////////
42 main(int argc
, char *argv
[])
45 token_type::position_type
pos("<testdata>");
47 #if defined(TESTLEXERS_TIMING)
48 boost::high_resolution_timer tim
;
49 for (int i
= 0; i
< 1000; ++i
) {
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
);
56 lexer_type it
= lexer_type(instr
.begin(), instr
.end(), pos
,
57 boost::wave::support_option_long_long
);
58 lexer_type end
= lexer_type();
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
;
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
))
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()
82 #if defined(TESTLEXERS_TIMING)
84 std::cout
<< tim
.elapsed() << " [s]" << std::endl
;
87 catch (boost::wave::cpplexer::lexing_exception
&e
) {
90 << "test_re2c_lexer: "
91 << e
.description() << std::endl
;
92 return (std::numeric_limits
<int>::max
)() - 1;
95 return boost::report_errors();