1 /*=============================================================================
2 Copyright (c) 2014 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)
6 =============================================================================*/
7 #if !defined(SPIRIT_X3_RAW_APRIL_9_2007_0912AM)
8 #define SPIRIT_X3_RAW_APRIL_9_2007_0912AM
10 #include <boost/spirit/home/x3/core/skip_over.hpp>
11 #include <boost/spirit/home/x3/core/parser.hpp>
12 #include <boost/spirit/home/x3/support/traits/move_to.hpp>
13 #include <boost/range/iterator_range.hpp>
15 namespace boost { namespace spirit { namespace x3
17 // this is a pseudo attribute type indicating that the parser wants the
18 // iterator range pointing to the [first, last) matching characters from
19 // the input iterators.
20 struct raw_attribute_type {};
22 template <typename Subject>
23 struct raw_directive : unary_parser<Subject, raw_directive<Subject>>
25 typedef unary_parser<Subject, raw_directive<Subject> > base_type;
26 typedef raw_attribute_type attribute_type;
27 static bool const handles_container = Subject::handles_container;
28 typedef Subject subject_type;
30 raw_directive(Subject const& subject)
31 : base_type(subject) {}
33 template <typename Iterator, typename Context
34 , typename RContext, typename Attribute>
35 bool parse(Iterator& first, Iterator const& last
36 , Context const& context, RContext& rcontext, Attribute& attr) const
38 x3::skip_over(first, last, context);
40 if (this->subject.parse(i, last, context, rcontext, unused))
42 traits::move_to(first, i, attr);
49 template <typename Iterator, typename Context, typename RContext>
50 bool parse(Iterator& first, Iterator const& last
51 , Context const& context, RContext& rcontext, unused_type) const
53 return this->subject.parse(first, last, context, rcontext, unused);
59 template <typename Subject>
60 raw_directive<typename extension::as_parser<Subject>::value_type>
61 operator[](Subject const& subject) const
63 return { as_parser(subject) };
67 auto const raw = raw_gen{};