1 | #include <iostream>
|
---|
2 | #include <iomanip>
|
---|
3 |
|
---|
4 | #include <boost/wave.hpp>
|
---|
5 | #include <boost/wave/token_ids.hpp>
|
---|
6 | #include <boost/wave/cpplexer/cpp_lex_token.hpp>
|
---|
7 | #include <boost/wave/cpplexer/cpp_lex_iterator.hpp>
|
---|
8 |
|
---|
9 | #include <boost/spirit/include/support_istream_iterator.hpp>
|
---|
10 | #include <boost/wave/cpplexer/re2clex/cpp_re2c_lexer.hpp>
|
---|
11 |
|
---|
12 | typedef boost::wave::cpplexer::lex_token<> cpplexer_token_t;
|
---|
13 | typedef boost::wave::cpplexer::lex_iterator<cpplexer_token_t> cpplexer_iterator_t;
|
---|
14 |
|
---|
15 | int main() {
|
---|
16 |
|
---|
17 | std::string cppstr{"struct Foo {};"};
|
---|
18 | auto cbeg = cppstr.begin();
|
---|
19 | auto cend = cppstr.end();
|
---|
20 | using namespace boost::wave;
|
---|
21 |
|
---|
22 | // works
|
---|
23 | cpplexer_iterator_t beg(cbeg, cend,
|
---|
24 | cpplexer_token_t::position_type("fake.cpp"),
|
---|
25 | language_support(support_cpp|support_cpp0x));
|
---|
26 | cpplexer_iterator_t end;
|
---|
27 |
|
---|
28 | for (auto tok = beg; tok != end; ++tok) {
|
---|
29 | std::cout << tok->get_value();
|
---|
30 | }
|
---|
31 | cbeg = cppstr.begin();
|
---|
32 |
|
---|
33 |
|
---|
34 | // does not work
|
---|
35 | std::stringstream ss(cppstr);
|
---|
36 | ss.unsetf(std::ios::skipws);
|
---|
37 | boost::spirit::istream_iterator mpbeg(ss);
|
---|
38 | boost::spirit::istream_iterator mpend;
|
---|
39 |
|
---|
40 | cpplexer_iterator_t beg2(mpbeg, mpend,
|
---|
41 | cpplexer_token_t::position_type("fake.cpp"),
|
---|
42 | language_support(support_cpp|support_cpp0x));
|
---|
43 |
|
---|
44 | // throws boost::wave::lexing_exception
|
---|
45 | for (auto tok = beg2; tok != end; ++tok) {
|
---|
46 | std::cout << tok->get_value();
|
---|
47 | }
|
---|
48 |
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 | // manually instantiate necessary template
|
---|
53 | template struct boost::wave::cpplexer::new_lexer_gen<boost::spirit::istream_iterator>;
|
---|