]> git.sesse.net Git - casparcg/blob - dependencies/boost/boost/spirit/home/lex/lexer/action.hpp
Manually merged pull request #222
[casparcg] / dependencies / 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 #if !defined(SPIRIT_LEX_ACTION_NOV_18_2007_0743PM)
7 #define SPIRIT_LEX_ACTION_NOV_18_2007_0743PM
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     private:
55         // silence MSVC warning C4512: assignment operator could not be generated
56         action& operator= (action const&);
57     };
58
59 }}}
60
61 ///////////////////////////////////////////////////////////////////////////////
62 namespace boost { namespace spirit
63 {
64     ///////////////////////////////////////////////////////////////////////////
65     // Karma action meta-compiler
66     template <>
67     struct make_component<lex::domain, tag::action>
68     {
69         template <typename Sig>
70         struct result;
71
72         template <typename This, typename Elements, typename Modifiers>
73         struct result<This(Elements, Modifiers)>
74         {
75             typedef typename
76                 remove_const<typename Elements::car_type>::type
77             subject_type;
78
79             typedef typename
80                 remove_const<typename Elements::cdr_type::car_type>::type
81             action_type;
82
83             typedef lex::action<subject_type, action_type> type;
84         };
85
86         template <typename Elements>
87         typename result<make_component(Elements, unused_type)>::type
88         operator()(Elements const& elements, unused_type) const
89         {
90             typename result<make_component(Elements, unused_type)>::type
91                 result(elements.car, elements.cdr.car);
92             return result;
93         }
94     };
95 }}
96
97 #endif