]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/include/boost/spirit/home/lex/qi/plain_raw_token.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / spirit / include / boost / spirit / home / lex / qi / plain_raw_token.hpp
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_SPIRIT_LEX_PLAIN_RAW_TOKEN_JUN_03_2011_0853PM)
7 #define BOOST_SPIRIT_LEX_PLAIN_RAW_TOKEN_JUN_03_2011_0853PM
8
9 #if defined(_MSC_VER)
10 #pragma once
11 #endif
12
13 #include <boost/spirit/home/support/info.hpp>
14 #include <boost/spirit/home/qi/detail/attributes.hpp>
15 #include <boost/spirit/home/support/common_terminals.hpp>
16 #include <boost/spirit/home/support/handles_container.hpp>
17 #include <boost/spirit/home/qi/skip_over.hpp>
18 #include <boost/spirit/home/qi/domain.hpp>
19 #include <boost/spirit/home/qi/parser.hpp>
20 #include <boost/spirit/home/qi/meta_compiler.hpp>
21 #include <boost/spirit/home/qi/detail/assign_to.hpp>
22 #include <boost/range/iterator_range.hpp>
23 #include <boost/fusion/include/vector.hpp>
24 #include <boost/fusion/include/at.hpp>
25 #include <boost/mpl/or.hpp>
26 #include <boost/type_traits/is_integral.hpp>
27 #include <boost/type_traits/is_enum.hpp>
28 #include <boost/lexical_cast.hpp>
29
30 namespace boost { namespace spirit
31 {
32 ///////////////////////////////////////////////////////////////////////////
33 // Enablers
34 ///////////////////////////////////////////////////////////////////////////
35
36 // enables raw_token
37 template <>
38 struct use_terminal<qi::domain, tag::raw_token>
39 : mpl::true_ {};
40
41 // enables raw_token(id)
42 template <typename A0>
43 struct use_terminal<qi::domain
44 , terminal_ex<tag::raw_token, fusion::vector1<A0> >
45 > : mpl::or_<is_integral<A0>, is_enum<A0> > {};
46
47 // enables *lazy* raw_token(id)
48 template <>
49 struct use_lazy_terminal<
50 qi::domain, tag::raw_token, 1
51 > : mpl::true_ {};
52 }}
53
54 namespace boost { namespace spirit { namespace qi
55 {
56 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
57 using spirit::raw_token;
58 #endif
59 using spirit::raw_token_type;
60
61 ///////////////////////////////////////////////////////////////////////////
62 template <typename TokenId>
63 struct plain_raw_token
64 : primitive_parser<plain_raw_token<TokenId> >
65 {
66 template <typename Context, typename Iterator>
67 struct attribute
68 {
69 typedef unused_type type;
70 };
71
72 plain_raw_token(TokenId const& id)
73 : id(id) {}
74
75 template <typename Iterator, typename Context
76 , typename Skipper, typename Attribute>
77 bool parse(Iterator& first, Iterator const& last
78 , Context& /*context*/, Skipper const& skipper
79 , Attribute& attr) const
80 {
81 qi::skip_over(first, last, skipper); // always do a pre-skip
82
83 if (first != last) {
84 // simply match the token id with the id this component has
85 // been initialized with
86
87 typedef typename
88 boost::detail::iterator_traits<Iterator>::value_type
89 token_type;
90 typedef typename token_type::id_type id_type;
91
92 token_type const& t = *first;
93 if (id_type(~0) == id_type(id) || id_type(id) == t.id()) {
94 spirit::traits::assign_to(t, attr);
95 ++first;
96 return true;
97 }
98 }
99 return false;
100 }
101
102 template <typename Context>
103 info what(Context& /*context*/) const
104 {
105 return info("raw_token",
106 "raw_token(" + boost::lexical_cast<utf8_string>(id) + ")");
107 }
108
109 TokenId id;
110 };
111
112 ///////////////////////////////////////////////////////////////////////////
113 // Parser generators: make_xxx function (objects)
114 ///////////////////////////////////////////////////////////////////////////
115 template <typename Modifiers>
116 struct make_primitive<tag::raw_token, Modifiers>
117 {
118 typedef plain_raw_token<std::size_t> result_type;
119
120 result_type operator()(unused_type, unused_type) const
121 {
122 return result_type(std::size_t(~0));
123 }
124 };
125
126 template <typename Modifiers, typename TokenId>
127 struct make_primitive<terminal_ex<tag::raw_token, fusion::vector1<TokenId> >
128 , Modifiers>
129 {
130 typedef plain_raw_token<TokenId> result_type;
131
132 template <typename Terminal>
133 result_type operator()(Terminal const& term, unused_type) const
134 {
135 return result_type(fusion::at_c<0>(term.args));
136 }
137 };
138 }}}
139
140 namespace boost { namespace spirit { namespace traits
141 {
142 ///////////////////////////////////////////////////////////////////////////
143 template<typename Idtype, typename Attr, typename Context, typename Iterator>
144 struct handles_container<qi::plain_raw_token<Idtype>, Attr, Context, Iterator>
145 : mpl::true_
146 {};
147 }}}
148
149 #endif