]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/spirit/test/lex/test.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / spirit / test / lex / test.hpp
CommitLineData
7c673cae
FG
1// Copyright (c) 2001-2011 Hartmut Kaiser
2//
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6#if !defined(BOOST_SPIRIT_LEX_TEST_MAR_23_2007_0721PM)
7#define BOOST_SPIRIT_LEX_TEST_MAR_23_2007_0721PM
8
9#include <boost/variant.hpp>
20effc67 10#include <boost/range/iterator_range_core.hpp>
7c673cae
FG
11
12namespace spirit_test
13{
14 ///////////////////////////////////////////////////////////////////////////
15 struct display_type
16 {
17 template<typename T>
18 void operator()(T const &) const
19 {
20 std::cout << typeid(T).name() << std::endl;
21 }
22
23 template<typename T>
24 static void print()
25 {
26 std::cout << typeid(T).name() << std::endl;
27 }
28 };
29
30 ///////////////////////////////////////////////////////////////////////////
31 display_type const display = {};
32
33 ///////////////////////////////////////////////////////////////////////////
34 template <typename Iterator>
35 inline boost::iterator_range<Iterator> const&
36 get_iterpair(boost::iterator_range<Iterator> const& itp)
37 {
38 return itp;
39 }
40
41 template <typename Iterator, BOOST_VARIANT_ENUM_PARAMS(typename T)>
42 inline boost::iterator_range<Iterator> const&
43 get_iterpair(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& v)
44 {
45 return boost::get<boost::iterator_range<Iterator> >(v);
46 }
47
48 ///////////////////////////////////////////////////////////////////////////
49 template <typename Lexer, typename Char>
50 inline bool
51 test(Lexer& lex, Char const* input, std::size_t token_id = 0,
52 Char const* state = NULL)
53 {
54 typedef typename Lexer::iterator_type iterator_type;
55 typedef std::basic_string<Char> string_type;
56
57 string_type str(input);
58 typename string_type::iterator it = str.begin();
59
60 iterator_type first = lex.begin(it, str.end());
61 iterator_type last = lex.end();
62
63 bool r = true;
64
65 if (NULL != state) {
66 std::size_t stateid = lex.map_state(state);
67 r = r && (static_cast<unsigned>(~0) != stateid);
68 first.set_state(stateid);
69 }
70
71 r = r && lex;
72 r = r && first != last;
73
74 if (token_id != 0)
75 r = r && (*first).id() == token_id;
76 else
77 r = r && (*first).id() != 0;
78
79 using namespace boost;
80
81 typedef typename Lexer::iterator_type::base_iterator_type iterator;
82 typedef iterator_range<iterator> iterpair_type;
83 iterpair_type const& ip = get_iterpair<iterator>((*first).value());
84
85 r = r && string_type(ip.begin(), ip.end()) == str;
86 return r && first != last && ++first == last;
87 }
88}
89
90#endif
91
92