]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/spirit/home/lex/lexer/action.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / spirit / home / lex / lexer / action.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 #ifndef BOOST_SPIRIT_LEX_LEXER_ACTION_HPP
7 #define BOOST_SPIRIT_LEX_LEXER_ACTION_HPP
8
9 #if defined(_MSC_VER)
10 #pragma once
11 #endif
12
13 #include <boost/spirit/home/lex/meta_compiler.hpp>
14 #include <boost/spirit/home/lex/lexer_type.hpp>
15 #include <boost/spirit/home/lex/argument.hpp>
16 #include <boost/spirit/home/lex/lexer/support_functions.hpp>
17 #include <boost/mpl/if.hpp>
18 #include <boost/type_traits/remove_const.hpp>
19 #include <boost/type_traits/is_same.hpp>
20
21 ///////////////////////////////////////////////////////////////////////////////
22 namespace boost { namespace spirit { namespace lex
23 {
24 ///////////////////////////////////////////////////////////////////////////
25 template <typename Subject, typename Action>
26 struct action : unary_lexer<action<Subject, Action> >
27 {
28 action(Subject const& subject, Action f)
29 : subject(subject), f(f) {}
30
31 template <typename LexerDef, typename String>
32 void collect(LexerDef& lexdef, String const& state
33 , String const& targetstate) const
34 {
35 // collect the token definition information for the token_def
36 // this action is attached to
37 subject.collect(lexdef, state, targetstate);
38 }
39
40 template <typename LexerDef>
41 void add_actions(LexerDef& lexdef) const
42 {
43 // call to add all actions attached further down the hierarchy
44 subject.add_actions(lexdef);
45
46 // retrieve the id of the associated token_def and register the
47 // given semantic action with the lexer instance
48 lexdef.add_action(subject.unique_id(), subject.state(), f);
49 }
50
51 Subject subject;
52 Action f;
53
54 // silence MSVC warning C4512: assignment operator could not be generated
55 BOOST_DELETED_FUNCTION(action& operator= (action const&))
56 };
57
58 }}}
59
60 ///////////////////////////////////////////////////////////////////////////////
61 namespace boost { namespace spirit
62 {
63 ///////////////////////////////////////////////////////////////////////////
64 // Karma action meta-compiler
65 template <>
66 struct make_component<lex::domain, tag::action>
67 {
68 template <typename Sig>
69 struct result;
70
71 template <typename This, typename Elements, typename Modifiers>
72 struct result<This(Elements, Modifiers)>
73 {
74 typedef typename
75 remove_const<typename Elements::car_type>::type
76 subject_type;
77
78 typedef typename
79 remove_const<typename Elements::cdr_type::car_type>::type
80 action_type;
81
82 typedef lex::action<subject_type, action_type> type;
83 };
84
85 template <typename Elements>
86 typename result<make_component(Elements, unused_type)>::type
87 operator()(Elements const& elements, unused_type) const
88 {
89 typename result<make_component(Elements, unused_type)>::type
90 result(elements.car, elements.cdr.car);
91 return result;
92 }
93 };
94 }}
95
96 #endif