Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/spirit/home/x3/nonterminal/rule.hpp @ 102:f46d142149f5
Whoops, finish that update
author | Chris Cannam |
---|---|
date | Mon, 07 Sep 2015 11:13:41 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
101:c530137014c0 | 102:f46d142149f5 |
---|---|
1 /*============================================================================= | |
2 Copyright (c) 2001-2014 Joel de Guzman | |
3 | |
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_X3_RULE_JAN_08_2012_0326PM) | |
8 #define BOOST_SPIRIT_X3_RULE_JAN_08_2012_0326PM | |
9 | |
10 #if defined(_MSC_VER) | |
11 #pragma once | |
12 #endif | |
13 | |
14 #include <boost/spirit/home/x3/nonterminal/detail/rule.hpp> | |
15 #include <boost/type_traits/is_same.hpp> | |
16 #include <boost/spirit/home/x3/support/context.hpp> | |
17 #include <boost/preprocessor/variadic/to_seq.hpp> | |
18 #include <boost/preprocessor/variadic/elem.hpp> | |
19 #include <boost/preprocessor/seq/for_each.hpp> | |
20 | |
21 #if !defined(BOOST_SPIRIT_X3_NO_RTTI) | |
22 #include <typeinfo> | |
23 #endif | |
24 | |
25 namespace boost { namespace spirit { namespace x3 | |
26 { | |
27 template <typename ID> | |
28 struct identity {}; | |
29 | |
30 // default parse_rule implementation | |
31 template <typename ID, typename Attribute, typename Iterator | |
32 , typename Context, typename ActualAttribute> | |
33 inline detail::default_parse_rule_result | |
34 parse_rule( | |
35 rule<ID, Attribute> rule_ | |
36 , Iterator& first, Iterator const& last | |
37 , Context const& context, ActualAttribute& attr) | |
38 { | |
39 static_assert(!is_same<decltype(get<ID>(context)), unused_type>::value, | |
40 "BOOST_SPIRIT_DEFINE undefined for this rule."); | |
41 return get<ID>(context).parse(first, last, context, unused, attr); | |
42 } | |
43 | |
44 template <typename ID, typename RHS, typename Attribute, bool force_attribute_> | |
45 struct rule_definition : parser<rule_definition<ID, RHS, Attribute, force_attribute_>> | |
46 { | |
47 typedef rule_definition<ID, RHS, Attribute, force_attribute_> this_type; | |
48 typedef ID id; | |
49 typedef RHS rhs_type; | |
50 typedef rule<ID, Attribute> lhs_type; | |
51 typedef Attribute attribute_type; | |
52 | |
53 static bool const has_attribute = | |
54 !is_same<Attribute, unused_type>::value; | |
55 static bool const handles_container = | |
56 traits::is_container<Attribute>::value; | |
57 static bool const force_attribute = | |
58 force_attribute_; | |
59 | |
60 rule_definition(RHS rhs, char const* name) | |
61 : rhs(rhs), name(name) {} | |
62 | |
63 template <typename Iterator, typename Context, typename Attribute_> | |
64 bool parse(Iterator& first, Iterator const& last | |
65 , Context const& context, unused_type, Attribute_& attr) const | |
66 { | |
67 return detail::rule_parser<attribute_type, ID> | |
68 ::call_rule_definition( | |
69 rhs, name, first, last | |
70 , context | |
71 , attr | |
72 , mpl::bool_<force_attribute>()); | |
73 } | |
74 | |
75 RHS rhs; | |
76 char const* name; | |
77 }; | |
78 | |
79 template <typename ID, typename Attribute> | |
80 struct rule : parser<rule<ID, Attribute>> | |
81 { | |
82 typedef ID id; | |
83 typedef Attribute attribute_type; | |
84 static bool const has_attribute = | |
85 !is_same<Attribute, unused_type>::value; | |
86 static bool const handles_container = | |
87 traits::is_container<Attribute>::value; | |
88 | |
89 #if !defined(BOOST_SPIRIT_X3_NO_RTTI) | |
90 rule() : name(typeid(rule).name()) {} | |
91 #else | |
92 rule() : name("unnamed") {} | |
93 #endif | |
94 | |
95 rule(char const* name) | |
96 : name(name) {} | |
97 | |
98 template <typename RHS> | |
99 rule_definition< | |
100 ID, typename extension::as_parser<RHS>::value_type, Attribute, false> | |
101 operator=(RHS const& rhs) const | |
102 { | |
103 return {as_parser(rhs), name}; | |
104 } | |
105 | |
106 template <typename RHS> | |
107 rule_definition< | |
108 ID, typename extension::as_parser<RHS>::value_type, Attribute, true> | |
109 operator%=(RHS const& rhs) const | |
110 { | |
111 return {as_parser(rhs), name}; | |
112 } | |
113 | |
114 | |
115 template <typename Iterator, typename Context, typename Attribute_> | |
116 bool parse(Iterator& first, Iterator const& last | |
117 , Context const& context, unused_type, Attribute_& attr) const | |
118 { | |
119 return parse_rule(*this, first, last, context, attr); | |
120 } | |
121 | |
122 char const* name; | |
123 }; | |
124 | |
125 namespace traits | |
126 { | |
127 template <typename T, typename Enable = void> | |
128 struct is_rule : mpl::false_ {}; | |
129 | |
130 template <typename ID, typename Attribute> | |
131 struct is_rule<rule<ID, Attribute>> : mpl::true_ {}; | |
132 | |
133 template <typename ID, typename Attribute, typename RHS, bool force_attribute> | |
134 struct is_rule<rule_definition<ID, RHS, Attribute, force_attribute>> : mpl::true_ {}; | |
135 } | |
136 | |
137 template <typename T> | |
138 struct get_info<T, typename enable_if<traits::is_rule<T>>::type> | |
139 { | |
140 typedef std::string result_type; | |
141 std::string operator()(T const& r) const | |
142 { | |
143 return r.name; | |
144 } | |
145 }; | |
146 | |
147 #define BOOST_SPIRIT_DECLARE_(r, data, rule_type) \ | |
148 template <typename Iterator, typename Context, typename Attribute> \ | |
149 bool parse_rule( \ | |
150 rule_type rule_ \ | |
151 , Iterator& first, Iterator const& last \ | |
152 , Context const& context, Attribute& attr); \ | |
153 /***/ | |
154 | |
155 #define BOOST_SPIRIT_DECLARE(...) BOOST_PP_SEQ_FOR_EACH( \ | |
156 BOOST_SPIRIT_DECLARE_, _, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)) \ | |
157 /***/ | |
158 | |
159 #define BOOST_SPIRIT_DEFINE_(r, data, def) \ | |
160 template <typename Iterator, typename Context, typename Attribute> \ | |
161 inline bool parse_rule( \ | |
162 decltype(def)::lhs_type rule_ \ | |
163 , Iterator& first, Iterator const& last \ | |
164 , Context const& context, Attribute& attr) \ | |
165 { \ | |
166 using boost::spirit::x3::unused; \ | |
167 auto const& def_ = (def); \ | |
168 return def_.parse(first, last, context, unused, attr); \ | |
169 } \ | |
170 /***/ | |
171 | |
172 #define BOOST_SPIRIT_DEFINE(...) BOOST_PP_SEQ_FOR_EACH( \ | |
173 BOOST_SPIRIT_DEFINE_, _, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)) \ | |
174 /***/ | |
175 | |
176 #define BOOST_SPIRIT_INSTANTIATE(rule_type, Iterator, Context) \ | |
177 template bool parse_rule<Iterator, Context, rule_type::attribute_type>( \ | |
178 rule_type rule_ \ | |
179 , Iterator& first, Iterator const& last \ | |
180 , Context const& context, rule_type::attribute_type& attr); \ | |
181 /***/ | |
182 | |
183 | |
184 }}} | |
185 | |
186 #endif |