• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #if defined(TESTLEXERS_TIMING)
15 #include <iostream>
16 #endif
17 
18 #include <limits>
19 
20 #include <boost/wave/wave_config.hpp>
21 #if !BOOST_WORKAROUND(__SUNPRO_CC, <= 0x580)
22 #undef BOOST_WAVE_SEPARATE_LEXER_INSTANTIATION
23 #endif
24 
25 #include <boost/detail/lightweight_test.hpp>
26 #if defined(TESTLEXERS_TIMING)
27 #include "high_resolution_timer.hpp"
28 #endif
29 
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
34 
35 typedef boost::wave::cpplexer::lex_token<> token_type;
36 typedef boost::wave::cpplexer::lex_iterator<token_type> lexer_type;
37 
38 ///////////////////////////////////////////////////////////////////////////////
39 //  include test data
40 #include "cpp_tokens.hpp"
41 
42 ///////////////////////////////////////////////////////////////////////////////
43 int
main(int argc,char * argv[])44 main(int argc, char *argv[])
45 {
46     try {
47         token_type::position_type pos("<testdata>");
48 
49 #if defined(TESTLEXERS_TIMING)
50         boost::high_resolution_timer tim;
51         for (int i = 0; i < 1000; ++i) {
52 #endif
53 
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);
57 
58         lexer_type it = lexer_type(instr.begin(), instr.end(), pos,
59             boost::wave::support_option_long_long);
60         lexer_type end = lexer_type();
61 
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;
65 #endif
66 
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))
73                     << std::endl;
74             }
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()
80                     << std::endl;
81             }
82         }
83 
84 #if defined(TESTLEXERS_TIMING)
85         }
86         std::cout << tim.elapsed() << " [s]" << std::endl;
87 #endif
88     }
89     catch (boost::wave::cpplexer::lexing_exception &e) {
90     // some lexing error
91         std::cerr
92             << "test_re2c_lexer: "
93             << e.description() << std::endl;
94         return (std::numeric_limits<int>::max)() - 1;
95     }
96 
97     return boost::report_errors();
98 }
99 
100