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(SPIRIT_SEQUENCE_JAN_06_2013_1015AM) 8 #define SPIRIT_SEQUENCE_JAN_06_2013_1015AM 9 10 #include <boost/spirit/home/x3/support/traits/attribute_of.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 namespace boost { namespace spirit { namespace x3 16 { 17 template <typename Left, typename Right> 18 struct sequence : binary_parser<Left, Right, sequence<Left, Right>> 19 { 20 typedef binary_parser<Left, Right, sequence<Left, Right>> base_type; 21 sequenceboost::spirit::x3::sequence22 sequence(Left const& left, Right const& right) 23 : base_type(left, right) {} 24 25 template <typename Iterator, typename Context, typename RContext> parseboost::spirit::x3::sequence26 bool parse( 27 Iterator& first, Iterator const& last 28 , Context const& context, RContext& rcontext, unused_type) const 29 { 30 Iterator save = first; 31 if (this->left.parse(first, last, context, rcontext, unused) 32 && this->right.parse(first, last, context, rcontext, unused)) 33 return true; 34 first = save; 35 return false; 36 } 37 38 template <typename Iterator, typename Context 39 , typename RContext, typename Attribute> parseboost::spirit::x3::sequence40 bool parse( 41 Iterator& first, Iterator const& last 42 , Context const& context, RContext& rcontext, Attribute& attr) const 43 { 44 return detail::parse_sequence(*this, first, last, context, rcontext, attr 45 , typename traits::attribute_category<Attribute>::type()); 46 } 47 }; 48 49 template <typename Left, typename Right> 50 inline sequence< 51 typename extension::as_parser<Left>::value_type 52 , typename extension::as_parser<Right>::value_type> operator >>(Left const & left,Right const & right)53 operator>>(Left const& left, Right const& right) 54 { 55 return { as_parser(left), as_parser(right) }; 56 } 57 58 template <typename Left, typename Right> operator >(Left const & left,Right const & right)59 auto operator>(Left const& left, Right const& right) 60 { 61 return left >> expect[right]; 62 } 63 }}} 64 65 namespace boost { namespace spirit { namespace x3 { namespace traits 66 { 67 template <typename Left, typename Right, typename Context> 68 struct attribute_of<x3::sequence<Left, Right>, Context> 69 : x3::detail::attribute_of_sequence<Left, Right, Context> {}; 70 }}}} 71 72 #endif 73