1 | // Copyright (c) 2001-2011 Hartmut Kaiser |
---|---|
2 | // Copyright (c) 2009 Pavel Baranov |
3 | // |
4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
6 | |
7 | #include <boost/spirit/include/lex_lexertl.hpp> |
8 | |
9 | #include <boost/core/lightweight_test.hpp> |
10 | |
11 | #include <iostream> |
12 | #include <string> |
13 | |
14 | using namespace boost::spirit; |
15 | using namespace boost::spirit::lex; |
16 | |
17 | typedef const char * base_iterator; |
18 | |
19 | /////////////////////////////////////////////////////////////////////////////// |
20 | // Token definition |
21 | /////////////////////////////////////////////////////////////////////////////// |
22 | template <typename Lexer> |
23 | struct position_helper_tokens : lexer<Lexer> |
24 | { |
25 | position_helper_tokens() |
26 | { |
27 | // define tokens and associate them with the lexer |
28 | eol = "\n"; |
29 | any = "[^\n]+"; |
30 | |
31 | // associate tokens with the lexer |
32 | this->self |
33 | = eol |
34 | | any |
35 | ; |
36 | } |
37 | |
38 | token_def<> any, eol; |
39 | }; |
40 | |
41 | int main() |
42 | { |
43 | // read input from the given file |
44 | std::string str ("test"); |
45 | |
46 | // token type |
47 | typedef lexertl::token<base_iterator, lex::omit, boost::mpl::false_> token_type; |
48 | |
49 | // lexer type |
50 | typedef lexertl::actor_lexer<token_type> lexer_type; |
51 | |
52 | // create the lexer object instance needed to invoke the lexical analysis |
53 | position_helper_tokens<lexer_type> position_helper_lexer; |
54 | |
55 | // tokenize the given string, all generated tokens are discarded |
56 | base_iterator first = str.c_str(); |
57 | base_iterator last = &first[str.size()]; |
58 | |
59 | for(lexer_type::iterator_type i = position_helper_lexer.begin(first, last); |
60 | i != position_helper_lexer.end() && (*i).is_valid(); i++ ) |
61 | { |
62 | } |
63 | return boost::report_errors(); |
64 | } |
65 | |
66 |