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_PP_IS_ITERATING)
7
8#if !defined(BOOST_SPIRIT_QI_TEST_ATTR_APR_23_2009_0605PM)
9#define BOOST_SPIRIT_QI_TEST_ATTR_APR_23_2009_0605PM
10
11#include <cstring>
12#include <string>
13#include <iterator>
14#include <iostream>
15#include <typeinfo>
16
17#include <boost/spirit/include/qi_parse.hpp>
18#include <boost/spirit/include/qi_what.hpp>
19
20#include <boost/core/lightweight_test.hpp>
21#include <boost/preprocessor/cat.hpp>
22#include <boost/preprocessor/iterate.hpp>
23#include <boost/preprocessor/repetition/repeat.hpp>
24#include <boost/preprocessor/repetition/enum_params.hpp>
25#include <boost/preprocessor/repetition/enum_binary_params.hpp>
26
27#define BOOST_PP_FILENAME_1 "test_attr.hpp"
28#define BOOST_PP_ITERATION_LIMITS (1, SPIRIT_ARGUMENTS_LIMIT)
29#include BOOST_PP_ITERATE()
30
31#endif
32
33///////////////////////////////////////////////////////////////////////////////
34//
35// Preprocessor vertical repetition code
36//
37///////////////////////////////////////////////////////////////////////////////
38#else // defined(BOOST_PP_IS_ITERATING)
39
40#define N BOOST_PP_ITERATION()
41#define DEFINE_ATTRIBUTE(z, n, _) \
42 BOOST_PP_CAT(A, n) BOOST_PP_CAT(attr, n) = BOOST_PP_CAT(A, n)();
43#define COMPARE_ATTRIBUTE(z, n, _) \
44 BOOST_PP_CAT(attr, n) == BOOST_PP_CAT(val, n) &&
45
46namespace spirit_test
47{
48 ///////////////////////////////////////////////////////////////////////////
49 template <typename Char, typename Parser
50 , BOOST_PP_ENUM_PARAMS(N, typename A)>
51 inline bool test(Char const *in, Parser const& p
52 , BOOST_PP_ENUM_BINARY_PARAMS(N, A, val))
53 {
54 namespace qi = boost::spirit::qi;
55
56 // we don't care about the result of the "what" function.
57 // we only care that all parsers have it:
58 qi::what(p);
59
60 Char const* last = in;
61 while (*last)
62 last++;
63
64 BOOST_PP_REPEAT(N, DEFINE_ATTRIBUTE, _);
65 bool result = qi::parse(in, last, p, BOOST_PP_ENUM_PARAMS(N, attr));
66
67 return result && BOOST_PP_REPEAT(N, COMPARE_ATTRIBUTE, _) in == last;
68 }
69
70 ///////////////////////////////////////////////////////////////////////////
71 template <typename Char, typename Parser, typename Skipper
72 , BOOST_PP_ENUM_PARAMS(N, typename A)>
73 inline bool test_skipped(Char const *in, Parser const& p
74 , Skipper const& skipper, BOOST_PP_ENUM_BINARY_PARAMS(N, A, val))
75 {
76 namespace qi = boost::spirit::qi;
77
78 // we don't care about the result of the "what" function.
79 // we only care that all parsers have it:
80 qi::what(p);
81
82 Char const* last = in;
83 while (*last)
84 last++;
85
86 BOOST_PP_REPEAT(N, DEFINE_ATTRIBUTE, _);
87 bool result = qi::phrase_parse(in, last, p, skipper
88 , BOOST_PP_ENUM_PARAMS(N, attr));
89
90 return result && BOOST_PP_REPEAT(N, COMPARE_ATTRIBUTE, _) in == last;
91 }
92
93 ///////////////////////////////////////////////////////////////////////////
94 template <typename Char, typename Parser, typename Skipper
95 , BOOST_PP_ENUM_PARAMS(N, typename A)>
96 inline bool test_postskipped(Char const *in, Parser const& p
97 , Skipper const& skipper
98 , BOOST_SCOPED_ENUM(boost::spirit::qi::skip_flag) post_skip
99 , BOOST_PP_ENUM_BINARY_PARAMS(N, A, val))
100 {
101 namespace qi = boost::spirit::qi;
102
103 // we don't care about the result of the "what" function.
104 // we only care that all parsers have it:
105 qi::what(p);
106
107 Char const* last = in;
108 while (*last)
109 last++;
110
111 BOOST_PP_REPEAT(N, DEFINE_ATTRIBUTE, _);
112 bool result = qi::phrase_parse(in, last, p, skipper, post_skip
113 , BOOST_PP_ENUM_PARAMS(N, attr));
114
115 return result && BOOST_PP_REPEAT(N, COMPARE_ATTRIBUTE, _) in == last;
116 }
117
118} // namespace spirit_test
119
120#undef COMPARE_ATTRIBUTE
121#undef DEFINE_ATTRIBUTE
122#undef N
123
124#endif
125

source code of boost/libs/spirit/test/qi/test_attr.hpp