• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/detail/lightweight_test.hpp>
8 #include <boost/spirit/include/lex_lexertl.hpp>
9 
10 #include <iostream>
11 #include <string>
12 
13 using namespace boost::spirit;
14 using namespace boost::spirit::lex;
15 
16 typedef const char * base_iterator;
17 
18 ///////////////////////////////////////////////////////////////////////////////
19 //  Token definition
20 ///////////////////////////////////////////////////////////////////////////////
21 template <typename Lexer>
22 struct position_helper_tokens : lexer<Lexer>
23 {
position_helper_tokensposition_helper_tokens24     position_helper_tokens()
25     {
26         // define tokens and associate them with the lexer
27         eol = "\n";
28         any = "[^\n]+";
29 
30         // associate tokens with the lexer
31         this->self
32             =   eol
33             |   any
34             ;
35     }
36 
37     token_def<> any, eol;
38 };
39 
main()40 int main()
41 {
42     // read input from the given file
43     std::string str ("test");
44 
45     // token type
46     typedef lexertl::token<base_iterator, lex::omit, boost::mpl::false_> token_type;
47 
48     // lexer type
49     typedef lexertl::actor_lexer<token_type> lexer_type;
50 
51     // create the lexer object instance needed to invoke the lexical analysis
52     position_helper_tokens<lexer_type> position_helper_lexer;
53 
54     // tokenize the given string, all generated tokens are discarded
55     base_iterator first = str.c_str();
56     base_iterator last = &first[str.size()];
57 
58     for(lexer_type::iterator_type i = position_helper_lexer.begin(first, last);
59         i != position_helper_lexer.end() && (*i).is_valid(); i++ )
60     {
61     }
62     return boost::report_errors();
63 }
64 
65