File indexing completed on 2025-02-27 09:55:39
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_SPIRIT_X3_DIRECTIVE_WITH_HPP
0008 #define BOOST_SPIRIT_X3_DIRECTIVE_WITH_HPP
0009
0010 #include <boost/spirit/home/x3/support/unused.hpp>
0011 #include <boost/spirit/home/x3/core/parser.hpp>
0012
0013 namespace boost { namespace spirit { namespace x3
0014 {
0015
0016
0017
0018 template <typename Subject, typename Derived, typename T>
0019 struct with_value_holder
0020 : unary_parser<Subject, Derived>
0021 {
0022 typedef unary_parser<Subject, Derived> base_type;
0023 mutable T val;
0024 constexpr with_value_holder(Subject const& subject, T&& val)
0025 : base_type(subject)
0026 , val(std::forward<T>(val)) {}
0027 };
0028
0029 template <typename Subject, typename Derived, typename T>
0030 struct with_value_holder<Subject, Derived, T&>
0031 : unary_parser<Subject, Derived>
0032 {
0033 typedef unary_parser<Subject, Derived> base_type;
0034 T& val;
0035 constexpr with_value_holder(Subject const& subject, T& val)
0036 : base_type(subject)
0037 , val(val) {}
0038 };
0039
0040 template <typename Subject, typename ID, typename T>
0041 struct with_directive
0042 : with_value_holder<Subject, with_directive<Subject, ID, T>, T>
0043 {
0044 typedef with_value_holder<Subject, with_directive<Subject, ID, T>, T> base_type;
0045 static bool const is_pass_through_unary = true;
0046 static bool const handles_container = Subject::handles_container;
0047
0048 typedef Subject subject_type;
0049
0050 constexpr with_directive(Subject const& subject, T&& val)
0051 : base_type(subject, std::forward<T>(val)) {}
0052
0053 template <typename Iterator, typename Context
0054 , typename RContext, typename Attribute>
0055 bool parse(Iterator& first, Iterator const& last
0056 , Context const& context, RContext& rcontext, Attribute& attr) const
0057 {
0058 return this->subject.parse(
0059 first, last
0060 , make_context<ID>(this->val, context)
0061 , rcontext
0062 , attr);
0063 }
0064 };
0065
0066 template <typename ID, typename T>
0067 struct with_gen
0068 {
0069 T&& val;
0070
0071 template <typename Subject>
0072 constexpr with_directive<typename extension::as_parser<Subject>::value_type, ID, T>
0073 operator[](Subject const& subject) const
0074 {
0075 return { as_parser(subject), std::forward<T>(val) };
0076 }
0077 };
0078
0079 template <typename ID, typename T>
0080 constexpr with_gen<ID, T> with(T&& val)
0081 {
0082 return { std::forward<T>(val) };
0083 }
0084 }}}
0085
0086 #endif