]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/qi/test.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / spirit / test / qi / test.hpp
1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
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 #if !defined(BOOST_SPIRIT_TEST_FEBRUARY_01_2007_0605PM)
8 #define BOOST_SPIRIT_TEST_FEBRUARY_01_2007_0605PM
9
10 #include <boost/spirit/include/qi_parse.hpp>
11 #include <boost/spirit/include/qi_what.hpp>
12 #include <boost/variant/apply_visitor.hpp>
13 #include <boost/foreach.hpp>
14 #include <iostream>
15
16 namespace spirit_test
17 {
18 template <typename Char, typename Parser>
19 bool test(Char const* in, Parser const& p, bool full_match = true)
20 {
21 // we don't care about the result of the "what" function.
22 // we only care that all parsers have it:
23 boost::spirit::qi::what(p);
24
25 Char const* last = in;
26 while (*last)
27 last++;
28 return boost::spirit::qi::parse(in, last, p)
29 && (!full_match || (in == last));
30 }
31
32 template <typename Char, typename Parser, typename Skipper>
33 bool test(Char const* in, Parser const& p
34 , Skipper const& s, bool full_match = true)
35 {
36 // we don't care about the result of the "what" function.
37 // we only care that all parsers have it:
38 boost::spirit::qi::what(p);
39
40 Char const* last = in;
41 while (*last)
42 last++;
43 return boost::spirit::qi::phrase_parse(in, last, p, s)
44 && (!full_match || (in == last));
45 }
46
47 template <typename Char, typename Parser>
48 bool binary_test(Char const* in, std::size_t size, Parser const& p,
49 bool full_match = true)
50 {
51 // we don't care about the result of the "what" function.
52 // we only care that all parsers have it:
53 boost::spirit::qi::what(p);
54
55 Char const* last = in + size;
56 return boost::spirit::qi::parse(in, last, p)
57 && (!full_match || (in == last));
58 }
59
60 template <typename Char, typename Parser, typename Skipper>
61 bool binary_test(Char const* in, std::size_t size, Parser const& p,
62 Skipper const& s, bool full_match = true)
63 {
64 // we don't care about the result of the "what" function.
65 // we only care that all parsers have it:
66 boost::spirit::qi::what(p);
67
68 Char const* last = in + size;
69 return boost::spirit::qi::phrase_parse(in, last, p, s)
70 && (!full_match || (in == last));
71 }
72
73 template <typename Char, typename Parser, typename Attr>
74 bool test_attr(Char const* in, Parser const& p
75 , Attr& attr, bool full_match = true)
76 {
77 // we don't care about the result of the "what" function.
78 // we only care that all parsers have it:
79 boost::spirit::qi::what(p);
80
81 Char const* last = in;
82 while (*last)
83 last++;
84 return boost::spirit::qi::parse(in, last, p, attr)
85 && (!full_match || (in == last));
86 }
87
88 template <typename Char, typename Parser, typename Attr, typename Skipper>
89 bool test_attr(Char const* in, Parser const& p
90 , Attr& attr, Skipper const& s, bool full_match = true)
91 {
92 // we don't care about the result of the "what" function.
93 // we only care that all parsers have it:
94 boost::spirit::qi::what(p);
95
96 Char const* last = in;
97 while (*last)
98 last++;
99 return boost::spirit::qi::phrase_parse(in, last, p, s, attr)
100 && (!full_match || (in == last));
101 }
102
103 template <typename Char, typename Parser, typename Attr>
104 bool binary_test_attr(Char const* in, std::size_t size, Parser const& p,
105 Attr& attr, bool full_match = true)
106 {
107 // we don't care about the result of the "what" function.
108 // we only care that all parsers have it:
109 boost::spirit::qi::what(p);
110
111 Char const* last = in + size;
112 return boost::spirit::qi::parse(in, last, p, attr)
113 && (!full_match || (in == last));
114 }
115
116 template <typename Char, typename Parser, typename Attr, typename Skipper>
117 bool binary_test_attr(Char const* in, std::size_t size, Parser const& p,
118 Attr& attr, Skipper const& s, bool full_match = true)
119 {
120 // we don't care about the result of the "what" function.
121 // we only care that all parsers have it:
122 boost::spirit::qi::what(p);
123
124 Char const* last = in + size;
125 return boost::spirit::qi::phrase_parse(in, last, p, s, attr)
126 && (!full_match || (in == last));
127 }
128
129 struct printer
130 {
131 typedef boost::spirit::utf8_string string;
132
133 void element(string const& tag, string const& value, int depth) const
134 {
135 for (int i = 0; i < (depth*4); ++i) // indent to depth
136 std::cout << ' ';
137
138 std::cout << "tag: " << tag;
139 if (value != "")
140 std::cout << ", value: " << value;
141 std::cout << std::endl;
142 }
143 };
144
145 void print_info(boost::spirit::info const& what)
146 {
147 using boost::spirit::basic_info_walker;
148
149 printer pr;
150 basic_info_walker<printer> walker(pr, what.tag, 0);
151 boost::apply_visitor(walker, what.value);
152 }
153 }
154
155 #endif