// Copyright (c) 2001-2011 Hartmut Kaiser // // 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) #if !defined(BOOST_SPIRIT_LEX_TEST_MAR_23_2007_0721PM) #define BOOST_SPIRIT_LEX_TEST_MAR_23_2007_0721PM #include #include namespace spirit_test { /////////////////////////////////////////////////////////////////////////// struct display_type { template void operator()(T const &) const { std::cout << typeid(T).name() << std::endl; } template static void print() { std::cout << typeid(T).name() << std::endl; } }; /////////////////////////////////////////////////////////////////////////// display_type const display = {}; /////////////////////////////////////////////////////////////////////////// template inline boost::iterator_range const& get_iterpair(boost::iterator_range const& itp) { return itp; } template inline boost::iterator_range const& get_iterpair(boost::variant const& v) { return boost::get >(v); } /////////////////////////////////////////////////////////////////////////// template inline bool test(Lexer& lex, Char const* input, std::size_t token_id = 0, Char const* state = NULL) { typedef typename Lexer::iterator_type iterator_type; typedef std::basic_string string_type; string_type str(input); typename string_type::iterator it = str.begin(); iterator_type first = lex.begin(it, str.end()); iterator_type last = lex.end(); bool r = true; if (NULL != state) { std::size_t stateid = lex.map_state(state); r = r && (static_cast(~0) != stateid); first.set_state(stateid); } r = r && lex; r = r && first != last; if (token_id != 0) r = r && (*first).id() == token_id; else r = r && (*first).id() != 0; using namespace boost; typedef typename Lexer::iterator_type::base_iterator_type iterator; typedef iterator_range iterpair_type; iterpair_type const& ip = get_iterpair((*first).value()); r = r && string_type(ip.begin(), ip.end()) == str; return r && first != last && ++first == last; } } #endif