1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
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
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>
18 template <typename Char, typename Parser>
19 bool test(Char const* in, Parser const& p, bool full_match = true)
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);
25 Char const* last = in;
28 return boost::spirit::qi::parse(in, last, p)
29 && (!full_match || (in == last));
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)
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);
40 Char const* last = in;
43 return boost::spirit::qi::phrase_parse(in, last, p, s)
44 && (!full_match || (in == last));
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)
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);
55 Char const* last = in + size;
56 return boost::spirit::qi::parse(in, last, p)
57 && (!full_match || (in == last));
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)
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);
68 Char const* last = in + size;
69 return boost::spirit::qi::phrase_parse(in, last, p, s)
70 && (!full_match || (in == last));
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)
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);
81 Char const* last = in;
84 return boost::spirit::qi::parse(in, last, p, attr)
85 && (!full_match || (in == last));
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)
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);
96 Char const* last = in;
99 return boost::spirit::qi::phrase_parse(in, last, p, s, attr)
100 && (!full_match || (in == last));
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)
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);
111 Char const* last = in + size;
112 return boost::spirit::qi::parse(in, last, p, attr)
113 && (!full_match || (in == last));
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)
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);
124 Char const* last = in + size;
125 return boost::spirit::qi::phrase_parse(in, last, p, s, attr)
126 && (!full_match || (in == last));
131 typedef boost::spirit::utf8_string string;
133 void element(string const& tag, string const& value, int depth) const
135 for (int i = 0; i < (depth*4); ++i) // indent to depth
138 std::cout << "tag: " << tag;
140 std::cout << ", value: " << value;
141 std::cout << std::endl;
145 void print_info(boost::spirit::info const& what)
147 using boost::spirit::basic_info_walker;
150 basic_info_walker<printer> walker(pr, what.tag, 0);
151 boost::apply_visitor(walker, what.value);