Ticket #7563: test_wave1.cpp

File test_wave1.cpp, 1.3 KB (added by gongyiling3468@…, 10 years ago)
Line 
1// test_wave1.cpp : Defines the entry point for the console application.
2//
3
4#include "stdafx.h"
5#include <boost/wave.hpp>
6#include <slex_token.hpp>
7#include <slex_iterator.hpp>
8#include <boost/algorithm/string.hpp>
9#include <fstream>
10#include <string>
11
12#define M else\
13 +1
14
15int _tmain(int argc, _TCHAR* argv[])
16{
17 using namespace boost::wave::cpplexer;
18 using namespace boost::wave;
19 using namespace boost::wave::cpplexer::slex;
20 std::ifstream ifs("test_wave1.cpp", std::ios::binary | std::ios::in);
21 ifs.unsetf(std::ios::skipws);
22 std::string s = std::string(std::istream_iterator<char>(ifs),
23 std::istream_iterator<char>());
24 typedef slex_token<> token_type;
25
26 typedef slex_iterator<token_type> iter_type;
27 token_type::position_type pos;
28 iter_type iter(s.begin(), s.end(), pos, language_support(support_cpp | support_option_preserve_comments | support_option_emit_contnewlines ));
29 iter_type end = iter_type();
30 while (iter != end)
31 {
32 const token_type &t = *iter++;
33 std::string line = t.get_value().c_str();
34 token_id tid;
35 if (boost::starts_with(line, "else\\"))
36 {
37 tid = t;
38 std::cout << t.get_value(); // output "else\"
39 }
40 }
41 return 0;
42}
43