Changeset 54714


Ignore:
Timestamp:
Jul 6, 2009, 3:19:52 PM (9 years ago)
Author:
Hartmut Kaiser
Message:

Spirit: more work on new test/lex/set_token_value_phoenix.cpp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libs/spirit/test/lex/set_token_value_phoenix.cpp

    r54713 r54714  
    11//  Copyright (c) 2009 Carl Barron
    2 //  Copyright (c) 2001-2009 Hartmut Kaiser
    32//
    43//  Distributed under the Boost Software License, Version 1.0. (See accompanying
     
    65
    76#include <iostream>
     7#include <sstream>
     8
     9#include <boost/detail/lightweight_test.hpp>
    810#include <boost/spirit/include/lex.hpp>
    911#include <boost/spirit/include/lex_lexertl.hpp>
     
    1315namespace phoenix = boost::phoenix;
    1416
    15 template <class Lexer>
    16 struct multi_tokens:lex::lexer<Lexer>
     17///////////////////////////////////////////////////////////////////////////////
     18template <typename Lexer>
     19struct multi_tokens : lex::lexer<Lexer>
    1720{
    1821    int level;
     
    5659{
    5760    typedef bool result_type;
    58    
    59     template <class Token>
     61
     62    dumper(std::stringstream& strm) : strm(strm) {}
     63
     64    template <typename Token>
    6065    bool operator () (Token const &t)
    6166    {
    62         char x = (char)(t.id() - lex::min_token_id + 'a');
    63         std::cout << x;
     67        strm << (char)(t.id() - lex::min_token_id + 'a');
    6468        return true;
    6569    }
     70
     71    std::stringstream& strm;
    6672};
    6773
     74///////////////////////////////////////////////////////////////////////////////
    6875int main()
    6976{
    70     std::string in("AAABBC");
    71    
    72     typedef lex::lexertl::token<std::string::iterator,boost::mpl::vector0<> > token_type;
     77    typedef lex::lexertl::token<std::string::iterator> token_type;
    7378    typedef lex::lexertl::actor_lexer<token_type> base_lexer_type;
    7479    typedef multi_tokens<base_lexer_type> lexer_type;
    7580    typedef lexer_type::iterator_type iterator;
    7681
     82    std::string in("AAABBC");
     83    std::string::iterator first(in.begin());
     84    std::stringstream strm;
     85
    7786    lexer_type the_lexer;
    78     std::string::iterator first(in.begin());
    79     if(lex::tokenize(first, in.end(), the_lexer, dumper()))
    80     {
    81         std::cout << "\nlex worked\n";
    82     }
    83     else
    84     {
    85         std::cout << "lex failed\n";
    86     }
     87    BOOST_TEST(lex::tokenize(first, in.end(), the_lexer, dumper(strm)));
     88    BOOST_TEST(strm.str() == "aaabbddd");
     89
     90    return boost::report_errors();
    8791}
    8892
Note: See TracChangeset for help on using the changeset viewer.