File indexing completed on 2025-01-31 10:02:35
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_SPIRIT_X3_DIRECTIVE_RAW_HPP
0008 #define BOOST_SPIRIT_X3_DIRECTIVE_RAW_HPP
0009
0010 #include <boost/spirit/home/x3/core/skip_over.hpp>
0011 #include <boost/spirit/home/x3/core/parser.hpp>
0012 #include <boost/spirit/home/x3/support/traits/move_to.hpp>
0013 #include <boost/spirit/home/x3/support/traits/pseudo_attribute.hpp>
0014 #include <boost/range/iterator_range_core.hpp>
0015
0016 namespace boost { namespace spirit { namespace x3
0017 {
0018
0019
0020
0021 struct raw_attribute_type {};
0022
0023 template <typename Subject>
0024 struct raw_directive : unary_parser<Subject, raw_directive<Subject>>
0025 {
0026 typedef unary_parser<Subject, raw_directive<Subject> > base_type;
0027 typedef raw_attribute_type attribute_type;
0028 static bool const handles_container = true;
0029 typedef Subject subject_type;
0030
0031 constexpr raw_directive(Subject const& subject)
0032 : base_type(subject) {}
0033
0034 template <typename Iterator, typename Context
0035 , typename RContext, typename Attribute>
0036 bool parse(Iterator& first, Iterator const& last
0037 , Context const& context, RContext& rcontext, Attribute& attr) const
0038 {
0039 x3::skip_over(first, last, context);
0040 Iterator i = first;
0041 if (this->subject.parse(i, last, context, rcontext, unused))
0042 {
0043 traits::move_to(first, i, attr);
0044 first = i;
0045 return true;
0046 }
0047 return false;
0048 }
0049
0050 template <typename Iterator, typename Context, typename RContext>
0051 bool parse(Iterator& first, Iterator const& last
0052 , Context const& context, RContext& rcontext, unused_type) const
0053 {
0054 return this->subject.parse(first, last, context, rcontext, unused);
0055 }
0056 };
0057
0058 struct raw_gen
0059 {
0060 template <typename Subject>
0061 constexpr raw_directive<typename extension::as_parser<Subject>::value_type>
0062 operator[](Subject const& subject) const
0063 {
0064 return { as_parser(subject) };
0065 }
0066 };
0067
0068 constexpr auto raw = raw_gen{};
0069
0070 namespace traits
0071 {
0072 template <typename Context, typename Iterator>
0073 struct pseudo_attribute<Context, raw_attribute_type, Iterator>
0074 {
0075 using attribute_type = raw_attribute_type;
0076 using type = boost::iterator_range<Iterator>;
0077
0078 static type call(Iterator& first, Iterator const& last, attribute_type)
0079 {
0080 return { first, last };
0081 }
0082 };
0083 }
0084 }}}
0085
0086 #endif