1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
/*=============================================================================
Copyright (c) 2001-2011 Joel de Guzman
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#if !defined(BOOST_SPIRIT_META_COMPILER_OCTOBER_16_2008_0347PM)
#define BOOST_SPIRIT_META_COMPILER_OCTOBER_16_2008_0347PM
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/support/meta_compiler.hpp>
#include <boost/spirit/home/qi/domain.hpp>
#include <boost/spirit/home/qi/parser.hpp>
#include <boost/spirit/home/support/string_traits.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/fusion/include/at.hpp>
namespace boost { namespace spirit
{
template <typename T>
struct use_terminal<qi::domain, T
, typename enable_if<traits::is_parser<T> >::type> // enables parsers
: mpl::true_ {};
namespace qi
{
template <typename T, typename Modifiers, typename Enable = void>
struct make_primitive // by default, return it as-is
{
typedef T result_type;
template <typename T_>
T_& operator()(T_& val, unused_type) const
{
return val;
}
template <typename T_>
T_ const& operator()(T_ const& val, unused_type) const
{
return val;
}
};
template <typename Tag, typename Elements
, typename Modifiers, typename Enable = void>
struct make_composite;
template <typename Directive, typename Body
, typename Modifiers, typename Enable = void>
struct make_directive
{
typedef Body result_type;
result_type operator()(unused_type, Body const& body, unused_type) const
{
return body; // By default, a directive simply returns its subject
}
};
}
// Qi primitive meta-compiler
template <>
struct make_component<qi::domain, proto::tag::terminal>
{
template <typename Sig>
struct result;
template <typename This, typename Elements, typename Modifiers>
struct result<This(Elements, Modifiers)>
{
typedef typename qi::make_primitive<
typename remove_const<typename Elements::car_type>::type,
typename remove_reference<Modifiers>::type>::result_type
type;
};
template <typename Elements, typename Modifiers>
typename result<make_component(Elements, Modifiers)>::type
operator()(Elements const& elements, Modifiers const& modifiers) const
{
typedef typename remove_const<typename Elements::car_type>::type term;
return qi::make_primitive<term, Modifiers>()(elements.car, modifiers);
}
};
// Qi composite meta-compiler
template <typename Tag>
struct make_component<qi::domain, Tag>
{
template <typename Sig>
struct result;
template <typename This, typename Elements, typename Modifiers>
struct result<This(Elements, Modifiers)>
{
typedef typename
qi::make_composite<Tag, Elements,
typename remove_reference<Modifiers>::type>::result_type
type;
};
template <typename Elements, typename Modifiers>
typename result<make_component(Elements, Modifiers)>::type
operator()(Elements const& elements, Modifiers const& modifiers) const
{
return qi::make_composite<Tag, Elements, Modifiers>()(
elements, modifiers);
}
};
// Qi function meta-compiler
template <>
struct make_component<qi::domain, proto::tag::function>
{
template <typename Sig>
struct result;
template <typename This, typename Elements, typename Modifiers>
struct result<This(Elements, Modifiers)>
{
typedef typename
qi::make_composite<
typename remove_const<typename Elements::car_type>::type,
typename Elements::cdr_type,
typename remove_reference<Modifiers>::type
>::result_type
type;
};
template <typename Elements, typename Modifiers>
typename result<make_component(Elements, Modifiers)>::type
operator()(Elements const& elements, Modifiers const& modifiers) const
{
return qi::make_composite<
typename remove_const<typename Elements::car_type>::type,
typename Elements::cdr_type,
Modifiers>()(elements.cdr, modifiers);
}
};
// Qi directive meta-compiler
template <>
struct make_component<qi::domain, tag::directive>
{
template <typename Sig>
struct result;
template <typename This, typename Elements, typename Modifiers>
struct result<This(Elements, Modifiers)>
{
typedef typename
qi::make_directive<
typename remove_const<typename Elements::car_type>::type,
typename remove_const<typename Elements::cdr_type::car_type>::type,
typename remove_reference<Modifiers>::type
>::result_type
type;
};
template <typename Elements, typename Modifiers>
typename result<make_component(Elements, Modifiers)>::type
operator()(Elements const& elements, Modifiers const& modifiers) const
{
return qi::make_directive<
typename remove_const<typename Elements::car_type>::type,
typename remove_const<typename Elements::cdr_type::car_type>::type,
Modifiers>()(elements.car, elements.cdr.car, modifiers);
}
};
}}
#endif
|