annotate DEPENDENCIES/generic/include/boost/spirit/home/qi/meta_compiler.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 /*=============================================================================
Chris@16 2 Copyright (c) 2001-2011 Joel de Guzman
Chris@16 3
Chris@16 4 Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 6 ==============================================================================*/
Chris@16 7 #if !defined(BOOST_SPIRIT_META_COMPILER_OCTOBER_16_2008_0347PM)
Chris@16 8 #define BOOST_SPIRIT_META_COMPILER_OCTOBER_16_2008_0347PM
Chris@16 9
Chris@16 10 #if defined(_MSC_VER)
Chris@16 11 #pragma once
Chris@16 12 #endif
Chris@16 13
Chris@16 14 #include <boost/spirit/home/support/meta_compiler.hpp>
Chris@16 15 #include <boost/spirit/home/qi/domain.hpp>
Chris@16 16 #include <boost/spirit/home/qi/parser.hpp>
Chris@16 17 #include <boost/spirit/home/support/string_traits.hpp>
Chris@16 18 #include <boost/type_traits/remove_reference.hpp>
Chris@16 19 #include <boost/utility/enable_if.hpp>
Chris@16 20 #include <boost/fusion/include/at.hpp>
Chris@16 21
Chris@16 22 namespace boost { namespace spirit
Chris@16 23 {
Chris@16 24 template <typename T>
Chris@16 25 struct use_terminal<qi::domain, T
Chris@16 26 , typename enable_if<traits::is_parser<T> >::type> // enables parsers
Chris@16 27 : mpl::true_ {};
Chris@16 28
Chris@16 29 namespace qi
Chris@16 30 {
Chris@16 31 template <typename T, typename Modifiers, typename Enable = void>
Chris@16 32 struct make_primitive // by default, return it as-is
Chris@16 33 {
Chris@16 34 typedef T result_type;
Chris@16 35
Chris@16 36 template <typename T_>
Chris@16 37 T_& operator()(T_& val, unused_type) const
Chris@16 38 {
Chris@16 39 return val;
Chris@16 40 }
Chris@16 41
Chris@16 42 template <typename T_>
Chris@16 43 T_ const& operator()(T_ const& val, unused_type) const
Chris@16 44 {
Chris@16 45 return val;
Chris@16 46 }
Chris@16 47 };
Chris@16 48
Chris@16 49 template <typename Tag, typename Elements
Chris@16 50 , typename Modifiers, typename Enable = void>
Chris@16 51 struct make_composite;
Chris@16 52
Chris@16 53 template <typename Directive, typename Body
Chris@16 54 , typename Modifiers, typename Enable = void>
Chris@16 55 struct make_directive
Chris@16 56 {
Chris@16 57 typedef Body result_type;
Chris@16 58 result_type operator()(unused_type, Body const& body, unused_type) const
Chris@16 59 {
Chris@16 60 return body; // By default, a directive simply returns its subject
Chris@16 61 }
Chris@16 62 };
Chris@16 63 }
Chris@16 64
Chris@16 65 // Qi primitive meta-compiler
Chris@16 66 template <>
Chris@16 67 struct make_component<qi::domain, proto::tag::terminal>
Chris@16 68 {
Chris@16 69 template <typename Sig>
Chris@16 70 struct result;
Chris@16 71
Chris@16 72 template <typename This, typename Elements, typename Modifiers>
Chris@16 73 struct result<This(Elements, Modifiers)>
Chris@16 74 {
Chris@16 75 typedef typename qi::make_primitive<
Chris@16 76 typename remove_const<typename Elements::car_type>::type,
Chris@16 77 typename remove_reference<Modifiers>::type>::result_type
Chris@16 78 type;
Chris@16 79 };
Chris@16 80
Chris@16 81 template <typename Elements, typename Modifiers>
Chris@16 82 typename result<make_component(Elements, Modifiers)>::type
Chris@16 83 operator()(Elements const& elements, Modifiers const& modifiers) const
Chris@16 84 {
Chris@16 85 typedef typename remove_const<typename Elements::car_type>::type term;
Chris@16 86 return qi::make_primitive<term, Modifiers>()(elements.car, modifiers);
Chris@16 87 }
Chris@16 88 };
Chris@16 89
Chris@16 90 // Qi composite meta-compiler
Chris@16 91 template <typename Tag>
Chris@16 92 struct make_component<qi::domain, Tag>
Chris@16 93 {
Chris@16 94 template <typename Sig>
Chris@16 95 struct result;
Chris@16 96
Chris@16 97 template <typename This, typename Elements, typename Modifiers>
Chris@16 98 struct result<This(Elements, Modifiers)>
Chris@16 99 {
Chris@16 100 typedef typename
Chris@16 101 qi::make_composite<Tag, Elements,
Chris@16 102 typename remove_reference<Modifiers>::type>::result_type
Chris@16 103 type;
Chris@16 104 };
Chris@16 105
Chris@16 106 template <typename Elements, typename Modifiers>
Chris@16 107 typename result<make_component(Elements, Modifiers)>::type
Chris@16 108 operator()(Elements const& elements, Modifiers const& modifiers) const
Chris@16 109 {
Chris@16 110 return qi::make_composite<Tag, Elements, Modifiers>()(
Chris@16 111 elements, modifiers);
Chris@16 112 }
Chris@16 113 };
Chris@16 114
Chris@16 115 // Qi function meta-compiler
Chris@16 116 template <>
Chris@16 117 struct make_component<qi::domain, proto::tag::function>
Chris@16 118 {
Chris@16 119 template <typename Sig>
Chris@16 120 struct result;
Chris@16 121
Chris@16 122 template <typename This, typename Elements, typename Modifiers>
Chris@16 123 struct result<This(Elements, Modifiers)>
Chris@16 124 {
Chris@16 125 typedef typename
Chris@16 126 qi::make_composite<
Chris@16 127 typename remove_const<typename Elements::car_type>::type,
Chris@16 128 typename Elements::cdr_type,
Chris@16 129 typename remove_reference<Modifiers>::type
Chris@16 130 >::result_type
Chris@16 131 type;
Chris@16 132 };
Chris@16 133
Chris@16 134 template <typename Elements, typename Modifiers>
Chris@16 135 typename result<make_component(Elements, Modifiers)>::type
Chris@16 136 operator()(Elements const& elements, Modifiers const& modifiers) const
Chris@16 137 {
Chris@16 138 return qi::make_composite<
Chris@16 139 typename remove_const<typename Elements::car_type>::type,
Chris@16 140 typename Elements::cdr_type,
Chris@16 141 Modifiers>()(elements.cdr, modifiers);
Chris@16 142 }
Chris@16 143 };
Chris@16 144
Chris@16 145 // Qi directive meta-compiler
Chris@16 146 template <>
Chris@16 147 struct make_component<qi::domain, tag::directive>
Chris@16 148 {
Chris@16 149 template <typename Sig>
Chris@16 150 struct result;
Chris@16 151
Chris@16 152 template <typename This, typename Elements, typename Modifiers>
Chris@16 153 struct result<This(Elements, Modifiers)>
Chris@16 154 {
Chris@16 155 typedef typename
Chris@16 156 qi::make_directive<
Chris@16 157 typename remove_const<typename Elements::car_type>::type,
Chris@16 158 typename remove_const<typename Elements::cdr_type::car_type>::type,
Chris@16 159 typename remove_reference<Modifiers>::type
Chris@16 160 >::result_type
Chris@16 161 type;
Chris@16 162 };
Chris@16 163
Chris@16 164 template <typename Elements, typename Modifiers>
Chris@16 165 typename result<make_component(Elements, Modifiers)>::type
Chris@16 166 operator()(Elements const& elements, Modifiers const& modifiers) const
Chris@16 167 {
Chris@16 168 return qi::make_directive<
Chris@16 169 typename remove_const<typename Elements::car_type>::type,
Chris@16 170 typename remove_const<typename Elements::cdr_type::car_type>::type,
Chris@16 171 Modifiers>()(elements.car, elements.cdr.car, modifiers);
Chris@16 172 }
Chris@16 173 };
Chris@16 174
Chris@16 175 }}
Chris@16 176
Chris@16 177 #endif