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