• 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 #include <string>
15 #if defined(TESTLEXERS_TIMING)
16 #include <iostream>
17 #endif
18 #include <limits>
19 
20 #include <boost/wave/wave_config.hpp>
21 #include <boost/detail/lightweight_test.hpp>
22 #if defined(TESTLEXERS_TIMING)
23 #include "high_resolution_timer.hpp"
24 #endif
25 
26 ///////////////////////////////////////////////////////////////////////////////
27 //  include the Xpressive lexer related stuff
28 #include <boost/wave/cpplexer/cpp_lex_token.hpp>                  // token type
29 #include <libs/wave/samples/token_statistics/xlex/xlex_lexer.hpp> // lexer type
30 #include <libs/wave/samples/token_statistics/xlex_iterator.hpp>   // iterator
31 
32 typedef boost::wave::cpplexer::lex_token<> token_type;
33 typedef boost::wave::cpplexer::xlex::xlex_iterator<token_type> lexer_type;
34 
35 //  This instantiates the correct 'new_lexer' function, which generates the
36 //  C++ lexer used in this test.
37 template struct boost::wave::cpplexer::xlex::new_lexer_gen<std::string::iterator>;
38 
39 ///////////////////////////////////////////////////////////////////////////////
40 //  include test data
41 #include "cpp_tokens.hpp"
42 
43 ///////////////////////////////////////////////////////////////////////////////
44 int
main(int argc,char * argv[])45 main(int argc, char *argv[])
46 {
47     try {
48         token_type::position_type pos("<testdata>");
49 
50 #if defined(TESTLEXERS_TIMING)
51         boost::high_resolution_timer tim;
52         for (int i = 0; i < 10; ++i) {
53 #endif
54 
55         for (lexem const* data = lexems; NULL != data->token; ++data) {
56         // feed the token to the lexer
57         token_type::string_type instr(data->token);
58 
59         lexer_type it = lexer_type(instr.begin(), instr.end(), pos,
60             boost::wave::support_option_long_long);
61         lexer_type end = lexer_type();
62 
63         // verify the correct outcome of the tokenisation
64 #if defined(TESTLEXERS_VERBOSE)
65         std::cerr << boost::wave::get_token_name(data->id) << std::endl;
66 #endif
67 
68             if (data->id != boost::wave::token_id(*it)) {
69                 BOOST_TEST(data->id == boost::wave::token_id(*it));
70                 std::cerr << data->token << ": expected: "
71                     << boost::wave::get_token_name(data->id);
72                 std::cerr << ", found: "
73                     << boost::wave::get_token_name(boost::wave::token_id(*it))
74                     << std::endl;
75             }
76             BOOST_TEST(++it != end);
77             BOOST_TEST(boost::wave::T_EOF == boost::wave::token_id(*it));
78         }
79 
80 #if defined(TESTLEXERS_TIMING)
81         }
82         std::cout << tim.elapsed() << " [s]" << std::endl;
83 #endif
84     }
85     catch (boost::wave::cpplexer::lexing_exception &e) {
86     // some lexing error
87         std::cerr
88             << "test_xlex_lexer: "
89             << e.description() << std::endl;
90         return (std::numeric_limits<int>::max)() - 1;
91     }
92 
93     return boost::report_errors();
94 }
95 
96