1
/*=============================================================================
3
Copyright (c) 2002-2003 Joel de Guzman
4
Copyright (c) 2002-2003 Hartmut Kaiser
5
Copyright (c) 2003 Martin Wille
6
http://spirit.sourceforge.net/
8
Permission to copy, use, modify, sell and distribute this software is
9
granted provided this copyright notice appears in all copies. This
10
software is provided "as is" without express or implied warranty, and
11
with no claim as to its suitability for any purpose.
12
=============================================================================*/
13
#if !defined(BOOST_SPIRIT_PARSER_TRAITS_IPP)
14
#define BOOST_SPIRIT_PARSER_TRAITS_IPP
16
#include "boost/spirit/core/composite/operators.hpp"
18
///////////////////////////////////////////////////////////////////////////////
19
namespace boost { namespace spirit {
24
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
26
///////////////////////////////////////////////////////////////////////////
28
// from spirit 1.1 (copyright (c) 2001 Bruce Florman)
29
// various workarounds to support compile time decisions without partial
30
// template specialization whether a given type is an instance of a
31
// concrete parser type.
33
///////////////////////////////////////////////////////////////////////////
35
///////////////////////////////////////////////////////////////////////////
37
struct parser_type_traits
39
// Determine at compile time (without partial specialization)
40
// whether a given type is an instance of the alternative<A,B>
44
typedef struct { char dummy[1]; } size1_t;
45
typedef struct { char dummy[2]; } size2_t;
46
typedef struct { char dummy[3]; } size3_t;
47
typedef struct { char dummy[4]; } size4_t;
48
typedef struct { char dummy[5]; } size5_t;
49
typedef struct { char dummy[6]; } size6_t;
50
typedef struct { char dummy[7]; } size7_t;
51
typedef struct { char dummy[8]; } size8_t;
52
typedef struct { char dummy[9]; } size9_t;
53
typedef struct { char dummy[10]; } size10_t;
55
// the following functions need no implementation
56
template <typename A, typename B>
57
static size1_t test_(alternative<A, B> const&);
58
template <typename A, typename B>
59
static size2_t test_(sequence<A, B> const&);
60
template <typename A, typename B>
61
static size3_t test_(sequential_or<A, B> const&);
62
template <typename A, typename B>
63
static size4_t test_(intersection<A, B> const&);
64
template <typename A, typename B>
65
static size5_t test_(difference<A, B> const&);
66
template <typename A, typename B>
67
static size6_t test_(exclusive_or<A, B> const&);
69
static size7_t test_(optional<S> const&);
71
static size8_t test_(kleene_star<S> const&);
73
static size9_t test_(positive<S> const&);
75
static size10_t test_(...);
77
BOOST_STATIC_CONSTANT(bool,
78
is_alternative = (sizeof(size1_t) == sizeof(test_(t()))) );
79
BOOST_STATIC_CONSTANT(bool,
80
is_sequence = (sizeof(size2_t) == sizeof(test_(t()))) );
81
BOOST_STATIC_CONSTANT(bool,
82
is_sequential_or = (sizeof(size3_t) == sizeof(test_(t()))) );
83
BOOST_STATIC_CONSTANT(bool,
84
is_intersection = (sizeof(size4_t) == sizeof(test_(t()))) );
85
BOOST_STATIC_CONSTANT(bool,
86
is_difference = (sizeof(size5_t) == sizeof(test_(t()))) );
87
BOOST_STATIC_CONSTANT(bool,
88
is_exclusive_or = (sizeof(size6_t) == sizeof(test_(t()))) );
89
BOOST_STATIC_CONSTANT(bool,
90
is_optional = (sizeof(size7_t) == sizeof(test_(t()))) );
91
BOOST_STATIC_CONSTANT(bool,
92
is_kleene_star = (sizeof(size8_t) == sizeof(test_(t()))) );
93
BOOST_STATIC_CONSTANT(bool,
94
is_positive = (sizeof(size9_t) == sizeof(test_(t()))) );
99
///////////////////////////////////////////////////////////////////////////
100
struct parser_type_traits_base {
102
BOOST_STATIC_CONSTANT(bool, is_alternative = false);
103
BOOST_STATIC_CONSTANT(bool, is_sequence = false);
104
BOOST_STATIC_CONSTANT(bool, is_sequential_or = false);
105
BOOST_STATIC_CONSTANT(bool, is_intersection = false);
106
BOOST_STATIC_CONSTANT(bool, is_difference = false);
107
BOOST_STATIC_CONSTANT(bool, is_exclusive_or = false);
108
BOOST_STATIC_CONSTANT(bool, is_optional = false);
109
BOOST_STATIC_CONSTANT(bool, is_kleene_star = false);
110
BOOST_STATIC_CONSTANT(bool, is_positive = false);
113
template <typename ParserT>
114
struct parser_type_traits : public parser_type_traits_base {
116
// no definition here, fallback for all not explicitly mentioned parser
120
template <typename A, typename B>
121
struct parser_type_traits<alternative<A, B> >
122
: public parser_type_traits_base {
124
BOOST_STATIC_CONSTANT(bool, is_alternative = true);
127
template <typename A, typename B>
128
struct parser_type_traits<sequence<A, B> >
129
: public parser_type_traits_base {
131
BOOST_STATIC_CONSTANT(bool, is_sequence = true);
134
template <typename A, typename B>
135
struct parser_type_traits<sequential_or<A, B> >
136
: public parser_type_traits_base {
138
BOOST_STATIC_CONSTANT(bool, is_sequential_or = true);
141
template <typename A, typename B>
142
struct parser_type_traits<intersection<A, B> >
143
: public parser_type_traits_base {
145
BOOST_STATIC_CONSTANT(bool, is_intersection = true);
148
template <typename A, typename B>
149
struct parser_type_traits<difference<A, B> >
150
: public parser_type_traits_base {
152
BOOST_STATIC_CONSTANT(bool, is_difference = true);
155
template <typename A, typename B>
156
struct parser_type_traits<exclusive_or<A, B> >
157
: public parser_type_traits_base {
159
BOOST_STATIC_CONSTANT(bool, is_exclusive_or = true);
162
template <typename S>
163
struct parser_type_traits<optional<S> >
164
: public parser_type_traits_base {
166
BOOST_STATIC_CONSTANT(bool, is_optional = true);
169
template <typename S>
170
struct parser_type_traits<kleene_star<S> >
171
: public parser_type_traits_base {
173
BOOST_STATIC_CONSTANT(bool, is_kleene_star = true);
176
template <typename S>
177
struct parser_type_traits<positive<S> >
178
: public parser_type_traits_base {
180
BOOST_STATIC_CONSTANT(bool, is_positive = true);
183
#endif // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
186
///////////////////////////////////////////////////////////////////////////////
187
}} // namespace boost::spirit
189
#endif // !defined(BOOST_SPIRIT_PARSER_TRAITS_IPP)