1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
3 Copyright (c) 2001-2011 Hartmut Kaiser
4 http://spirit.sourceforge.net/
6 Distributed under the Boost Software License, Version 1.0. (See accompanying
7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 #if !defined(BOOST_SPIRIT_WRAP_ACTION_APR_19_2008_0103PM)
10 #define BOOST_SPIRIT_WRAP_ACTION_APR_19_2008_0103PM
16 #include <boost/spirit/include/phoenix_core.hpp>
17 #include <boost/spirit/include/phoenix_bind.hpp>
18 #include <boost/spirit/include/phoenix_scope.hpp>
20 #include <boost/spirit/home/support/attributes.hpp>
21 #include <boost/spirit/home/lex/lexer/pass_flags.hpp>
23 ///////////////////////////////////////////////////////////////////////////////
24 namespace boost { namespace spirit { namespace lex { namespace lexertl
28 template <typename FunctionType, typename Iterator, typename Context
32 // plain functions with 5 arguments, function objects (including
33 // phoenix actors) are not touched at all
35 static FunctionType call(F const& f)
40 // semantic actions with 4 arguments
42 static void arg4_action(F* f, Iterator& start, Iterator& end
43 , BOOST_SCOPED_ENUM(pass_flags)& pass, IdType& id
46 f(start, end, pass, id);
49 template <typename A0, typename A1, typename A2, typename A3>
50 static FunctionType call(void (*f)(A0, A1, A2, A3))
52 void (*pf)(void(*)(A0, A1, A2, A3)
53 , Iterator&, Iterator&, BOOST_SCOPED_ENUM(pass_flags)&
54 , IdType&, Context const&) = &wrap_action::arg4_action;
56 using phoenix::arg_names::_1;
57 using phoenix::arg_names::_2;
58 using phoenix::arg_names::_3;
59 using phoenix::arg_names::_4;
60 using phoenix::arg_names::_5;
61 return phoenix::bind(pf, f, _1, _2, _3, _4, _5);
64 // semantic actions with 3 arguments
66 static void arg3_action(F* f, Iterator& start, Iterator& end
67 , BOOST_SCOPED_ENUM(pass_flags)& pass, IdType
73 template <typename A0, typename A1, typename A2>
74 static FunctionType call(void (*f)(A0, A1, A2))
76 void (*pf)(void(*)(A0, A1, A2), Iterator&, Iterator&
77 , BOOST_SCOPED_ENUM(pass_flags)&, IdType
78 , Context const&) = &wrap_action::arg3_action;
80 using phoenix::arg_names::_1;
81 using phoenix::arg_names::_2;
82 using phoenix::arg_names::_3;
83 using phoenix::arg_names::_4;
84 using phoenix::arg_names::_5;
85 return phoenix::bind(pf, f, _1, _2, _3, _4, _5);
88 // semantic actions with 2 arguments
90 static void arg2_action(F* f, Iterator& start, Iterator& end
91 , BOOST_SCOPED_ENUM(pass_flags)&, IdType, Context const&)
96 template <typename A0, typename A1>
97 static FunctionType call(void (*f)(A0, A1))
99 void (*pf)(void(*)(A0, A1), Iterator&, Iterator&
100 , BOOST_SCOPED_ENUM(pass_flags)&
101 , IdType, Context const&) = &wrap_action::arg2_action;
103 using phoenix::arg_names::_1;
104 using phoenix::arg_names::_2;
105 using phoenix::arg_names::_3;
106 using phoenix::arg_names::_4;
107 using phoenix::arg_names::_5;
108 return phoenix::bind(pf, f, _1, _2, _3, _4, _5);
111 // we assume that either both iterators are to be passed to the
112 // semantic action or none iterator at all (i.e. it's not possible
113 // to have a lexer semantic action function taking one arguments).
115 // semantic actions with 0 argument
116 template <typename F>
117 static void arg0_action(F* f, Iterator&, Iterator&
118 , BOOST_SCOPED_ENUM(pass_flags)&, IdType, Context const&)
123 static FunctionType call(void (*f)())
125 void (*pf)(void(*)(), Iterator&, Iterator&
126 , BOOST_SCOPED_ENUM(pass_flags)&
127 , IdType, Context const&) = &arg0_action;
129 using phoenix::arg_names::_1;
130 using phoenix::arg_names::_2;
131 using phoenix::arg_names::_3;
132 using phoenix::arg_names::_4;
133 using phoenix::arg_names::_5;
134 return phoenix::bind(pf, f, _1, _2, _3, _4, _5);
138 // specialization allowing to skip wrapping for lexer types not
139 // supporting semantic actions
140 template <typename Iterator, typename Context, typename Idtype>
141 struct wrap_action<unused_type, Iterator, Context, Idtype>
143 // plain function objects are not touched at all
144 template <typename F>
145 static F const& call(F const& f)