| 1 | /*============================================================================= |
| 2 | Copyright (c) 2001-2014 Joel de Guzman |
| 3 | |
| 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(BOOST_SPIRIT_X3_SEQUENCE_JAN_06_2013_1015AM) |
| 8 | #define BOOST_SPIRIT_X3_SEQUENCE_JAN_06_2013_1015AM |
| 9 | |
| 10 | #include <boost/spirit/home/x3/support/traits/attribute_of_binary.hpp> |
| 11 | #include <boost/spirit/home/x3/core/parser.hpp> |
| 12 | #include <boost/spirit/home/x3/operator/detail/sequence.hpp> |
| 13 | #include <boost/spirit/home/x3/directive/expect.hpp> |
| 14 | |
| 15 | #include <boost/fusion/include/deque_fwd.hpp> |
| 16 | |
| 17 | namespace boost { namespace spirit { namespace x3 |
| 18 | { |
| 19 | template <typename Left, typename Right> |
| 20 | struct sequence : binary_parser<Left, Right, sequence<Left, Right>> |
| 21 | { |
| 22 | typedef binary_parser<Left, Right, sequence<Left, Right>> base_type; |
| 23 | |
| 24 | constexpr sequence(Left const& left, Right const& right) |
| 25 | : base_type(left, right) {} |
| 26 | |
| 27 | template <typename Iterator, typename Context, typename RContext> |
| 28 | bool parse( |
| 29 | Iterator& first, Iterator const& last |
| 30 | , Context const& context, RContext& rcontext, unused_type) const |
| 31 | { |
| 32 | Iterator save = first; |
| 33 | if (this->left.parse(first, last, context, rcontext, unused) |
| 34 | && this->right.parse(first, last, context, rcontext, unused)) |
| 35 | return true; |
| 36 | first = save; |
| 37 | return false; |
| 38 | } |
| 39 | |
| 40 | template <typename Iterator, typename Context |
| 41 | , typename RContext, typename Attribute> |
| 42 | bool parse( |
| 43 | Iterator& first, Iterator const& last |
| 44 | , Context const& context, RContext& rcontext, Attribute& attr) const |
| 45 | { |
| 46 | return detail::parse_sequence(*this, first, last, context, rcontext, attr |
| 47 | , typename traits::attribute_category<Attribute>::type()); |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | template <typename Left, typename Right> |
| 52 | constexpr sequence< |
| 53 | typename extension::as_parser<Left>::value_type |
| 54 | , typename extension::as_parser<Right>::value_type> |
| 55 | operator>>(Left const& left, Right const& right) |
| 56 | { |
| 57 | return { as_parser(left), as_parser(right) }; |
| 58 | } |
| 59 | |
| 60 | template <typename Left, typename Right> |
| 61 | constexpr auto operator>(Left const& left, Right const& right) |
| 62 | -> decltype(left >> expect[right]) |
| 63 | { |
| 64 | return left >> expect[right]; |
| 65 | } |
| 66 | }}} |
| 67 | |
| 68 | namespace boost { namespace spirit { namespace x3 { namespace traits |
| 69 | { |
| 70 | template <typename Left, typename Right, typename Context> |
| 71 | struct attribute_of<x3::sequence<Left, Right>, Context> |
| 72 | : x3::detail::attribute_of_binary<fusion::deque, x3::sequence, Left, Right, Context> {}; |
| 73 | }}}} |
| 74 | |
| 75 | #endif |
| 76 | |