// Copyright (c) 2001-2011 Hartmut Kaiser // Copyright (c) 2009 Pavel Baranov // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include #include #include #include using namespace boost::spirit; using namespace boost::spirit::lex; typedef const char * base_iterator; /////////////////////////////////////////////////////////////////////////////// // Token definition /////////////////////////////////////////////////////////////////////////////// template struct position_helper_tokens : lexer { position_helper_tokens() { // define tokens and associate them with the lexer eol = "\n"; any = "[^\n]+"; // associate tokens with the lexer this->self = eol | any ; } token_def<> any, eol; }; int main() { // read input from the given file std::string str ("test"); // token type typedef lexertl::token token_type; // lexer type typedef lexertl::actor_lexer lexer_type; // create the lexer object instance needed to invoke the lexical analysis position_helper_tokens position_helper_lexer; // tokenize the given string, all generated tokens are discarded base_iterator first = str.c_str(); base_iterator last = &first[str.size()]; for(lexer_type::iterator_type i = position_helper_lexer.begin(first, last); i != position_helper_lexer.end() && (*i).is_valid(); i++ ) { } return boost::report_errors(); }