1 // Copyright (c) 2001-2011 Hartmut Kaiser
2 // Copyright (c) 2001-2011 Joel de Guzman
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)
7 #if !defined(BOOST_SPIRIT_LEX_META_COMPILER_APR_20_2009_0756PM)
8 #define BOOST_SPIRIT_LEX_META_COMPILER_APR_20_2009_0756PM
14 #include <boost/spirit/home/support/meta_compiler.hpp>
15 #include <boost/spirit/home/lex/domain.hpp>
16 #include <boost/spirit/home/lex/lexer_type.hpp>
17 #include <boost/type_traits/remove_reference.hpp>
18 #include <boost/utility/enable_if.hpp>
20 namespace boost { namespace spirit
23 struct use_terminal<lex::domain, T
24 , typename enable_if<traits::is_lexer<T> >::type> // enables lexers
29 template <typename T, typename Modifiers, typename Enable = void>
30 struct make_primitive // by default, return it as-is
32 typedef T result_type;
34 template <typename T_>
35 T_& operator()(T_& val, unused_type) const
40 template <typename T_>
41 T_ const& operator()(T_ const& val, unused_type) const
47 template <typename Tag, typename Elements
48 , typename Modifiers, typename Enable = void>
49 struct make_composite;
52 // Lex primitive meta-compiler
54 struct make_component<lex::domain, proto::tag::terminal>
56 template <typename Sig>
59 template <typename This, typename Elements, typename Modifiers>
60 struct result<This(Elements, Modifiers)>
62 typedef typename lex::make_primitive<
63 typename remove_const<typename Elements::car_type>::type,
64 typename remove_reference<Modifiers>::type>::result_type
68 template <typename Elements, typename Modifiers>
69 typename result<make_component(Elements, Modifiers)>::type
70 operator()(Elements const& elements, Modifiers const& modifiers) const
72 typedef typename remove_const<typename Elements::car_type>::type term;
73 return lex::make_primitive<term, Modifiers>()(elements.car, modifiers);
77 // Lex composite meta-compiler
78 template <typename Tag>
79 struct make_component<lex::domain, Tag>
81 template <typename Sig>
84 template <typename This, typename Elements, typename Modifiers>
85 struct result<This(Elements, Modifiers)>
88 lex::make_composite<Tag, Elements
89 , typename remove_reference<Modifiers>::type>::result_type
93 template <typename Elements, typename Modifiers>
94 typename result<make_component(Elements, Modifiers)>::type
95 operator()(Elements const& elements, Modifiers const& modifiers) const
97 return lex::make_composite<Tag, Elements, Modifiers>()(