]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/spirit/repository/test/qi/test.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / spirit / repository / test / qi / test.hpp
CommitLineData
7c673cae
FG
1/*=============================================================================
2 Copyright (c) 2001-2010 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>
7c673cae
FG
13#include <iostream>
14
15namespace spirit_test
16{
17 template <typename Char, typename Parser>
18 bool test(Char const* in, Parser const& p, bool full_match = true)
19 {
20 // we don't care about the result of the "what" function.
21 // we only care that all parsers have it:
22 boost::spirit::qi::what(p);
23
24 Char const* last = in;
25 while (*last)
26 last++;
27 return boost::spirit::qi::parse(in, last, p)
28 && (!full_match || (in == last));
29 }
30
31 template <typename Char, typename Parser, typename Skipper>
32 bool test(Char const* in, Parser const& p
33 , Skipper const& s, bool full_match = true)
34 {
35 // we don't care about the result of the "what" function.
36 // we only care that all parsers have it:
37 boost::spirit::qi::what(p);
38
39 Char const* last = in;
40 while (*last)
41 last++;
42 return boost::spirit::qi::phrase_parse(in, last, p, s)
43 && (!full_match || (in == last));
44 }
45
46 template <typename Char, typename Parser, typename Attr>
47 bool test_attr(Char const* in, Parser const& p
48 , Attr& attr, bool full_match = true)
49 {
50 // we don't care about the result of the "what" function.
51 // we only care that all parsers have it:
52 boost::spirit::qi::what(p);
53
54 Char const* last = in;
55 while (*last)
56 last++;
57 return boost::spirit::qi::parse(in, last, p, attr)
58 && (!full_match || (in == last));
59 }
60
61 template <typename Char, typename Parser, typename Attr, typename Skipper>
62 bool test_attr(Char const* in, Parser const& p
63 , Attr& attr, Skipper const& s, bool full_match = true)
64 {
65 // we don't care about the result of the "what" function.
66 // we only care that all parsers have it:
67 boost::spirit::qi::what(p);
68
69 Char const* last = in;
70 while (*last)
71 last++;
72 return boost::spirit::qi::phrase_parse(in, last, p, s, attr)
73 && (!full_match || (in == last));
74 }
75
76 struct printer
77 {
78 typedef boost::spirit::utf8_string string;
79
80 void element(string const& tag, string const& value, int depth) const
81 {
82 for (int i = 0; i < (depth*4); ++i) // indent to depth
83 std::cout << ' ';
84
85 std::cout << "tag: " << tag;
86 if (value != "")
87 std::cout << ", value: " << value;
88 std::cout << std::endl;
89 }
90 };
91
92 void print_info(boost::spirit::info const& what)
93 {
94 using boost::spirit::basic_info_walker;
95
96 printer pr;
97 basic_info_walker<printer> walker(pr, what.tag, 0);
98 boost::apply_visitor(walker, what.value);
99 }
100}
101
102#endif