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_ALTERNATIVE_JAN_07_2013_1131AM)
8#define BOOST_SPIRIT_X3_ALTERNATIVE_JAN_07_2013_1131AM
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/alternative.hpp>
13
14#include <boost/variant/variant_fwd.hpp>
15
16namespace boost { namespace spirit { namespace x3
17{
18 template <typename Left, typename Right>
19 struct alternative : binary_parser<Left, Right, alternative<Left, Right>>
20 {
21 typedef binary_parser<Left, Right, alternative<Left, Right>> base_type;
22
23 constexpr alternative(Left const& left, Right const& right)
24 : base_type(left, right) {}
25
26 template <typename Iterator, typename Context, typename RContext>
27 bool parse(
28 Iterator& first, Iterator const& last
29 , Context const& context, RContext& rcontext, unused_type) const
30 {
31 return this->left.parse(first, last, context, rcontext, unused)
32 || this->right.parse(first, last, context, rcontext, unused);
33 }
34
35 template <typename Iterator, typename Context
36 , typename RContext, typename Attribute>
37 bool parse(
38 Iterator& first, Iterator const& last
39 , Context const& context, RContext& rcontext, Attribute& attr) const
40 {
41 return detail::parse_alternative(this->left, first, last, context, rcontext, attr)
42 || detail::parse_alternative(this->right, first, last, context, rcontext, attr);
43 }
44 };
45
46 template <typename Left, typename Right>
47 constexpr alternative<
48 typename extension::as_parser<Left>::value_type
49 , typename extension::as_parser<Right>::value_type>
50 operator|(Left const& left, Right const& right)
51 {
52 return { as_parser(left), as_parser(right) };
53 }
54}}}
55
56namespace boost { namespace spirit { namespace x3 { namespace traits
57{
58 template <typename Left, typename Right, typename Context>
59 struct attribute_of<x3::alternative<Left, Right>, Context>
60 : x3::detail::attribute_of_binary<boost::variant, x3::alternative, Left, Right, Context> {};
61}}}}
62
63#endif
64

source code of boost/libs/spirit/include/boost/spirit/home/x3/operator/alternative.hpp