Chris@102
|
1 /*=============================================================================
|
Chris@102
|
2 Copyright (c) 2001-2014 Joel de Guzman
|
Chris@102
|
3
|
Chris@102
|
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@102
|
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@102
|
6 =============================================================================*/
|
Chris@102
|
7 #if !defined(SPIRIT_ALTERNATIVE_JAN_07_2013_1131AM)
|
Chris@102
|
8 #define SPIRIT_ALTERNATIVE_JAN_07_2013_1131AM
|
Chris@102
|
9
|
Chris@102
|
10 #if defined(_MSC_VER)
|
Chris@102
|
11 #pragma once
|
Chris@102
|
12 #endif
|
Chris@102
|
13
|
Chris@102
|
14 #include <boost/spirit/home/x3/support/traits/attribute_of.hpp>
|
Chris@102
|
15 #include <boost/spirit/home/x3/core/parser.hpp>
|
Chris@102
|
16 #include <boost/spirit/home/x3/operator/detail/alternative.hpp>
|
Chris@102
|
17
|
Chris@102
|
18 namespace boost { namespace spirit { namespace x3
|
Chris@102
|
19 {
|
Chris@102
|
20 template <typename Left, typename Right>
|
Chris@102
|
21 struct alternative : binary_parser<Left, Right, alternative<Left, Right>>
|
Chris@102
|
22 {
|
Chris@102
|
23 typedef binary_parser<Left, Right, alternative<Left, Right>> base_type;
|
Chris@102
|
24
|
Chris@102
|
25 alternative(Left left, Right right)
|
Chris@102
|
26 : base_type(left, right) {}
|
Chris@102
|
27
|
Chris@102
|
28 template <typename Iterator, typename Context, typename RContext>
|
Chris@102
|
29 bool parse(
|
Chris@102
|
30 Iterator& first, Iterator const& last
|
Chris@102
|
31 , Context const& context, RContext& rcontext, unused_type) const
|
Chris@102
|
32 {
|
Chris@102
|
33 return this->left.parse(first, last, context, rcontext, unused)
|
Chris@102
|
34 || this->right.parse(first, last, context, rcontext, unused);
|
Chris@102
|
35 }
|
Chris@102
|
36
|
Chris@102
|
37 template <typename Iterator, typename Context
|
Chris@102
|
38 , typename RContext, typename Attribute>
|
Chris@102
|
39 bool parse(
|
Chris@102
|
40 Iterator& first, Iterator const& last
|
Chris@102
|
41 , Context const& context, RContext& rcontext, Attribute& attr) const
|
Chris@102
|
42 {
|
Chris@102
|
43 if (detail::parse_alternative(this->left, first, last, context, rcontext, attr))
|
Chris@102
|
44 return true;
|
Chris@102
|
45 if (detail::parse_alternative(this->right, first, last, context, rcontext, attr))
|
Chris@102
|
46 return true;
|
Chris@102
|
47 return false;
|
Chris@102
|
48 }
|
Chris@102
|
49 };
|
Chris@102
|
50
|
Chris@102
|
51 template <typename Left, typename Right>
|
Chris@102
|
52 inline alternative<
|
Chris@102
|
53 typename extension::as_parser<Left>::value_type
|
Chris@102
|
54 , typename extension::as_parser<Right>::value_type>
|
Chris@102
|
55 operator|(Left const& left, Right const& right)
|
Chris@102
|
56 {
|
Chris@102
|
57 return {as_parser(left), as_parser(right)};
|
Chris@102
|
58 }
|
Chris@102
|
59 }}}
|
Chris@102
|
60
|
Chris@102
|
61 namespace boost { namespace spirit { namespace x3 { namespace traits
|
Chris@102
|
62 {
|
Chris@102
|
63 template <typename Left, typename Right, typename Context>
|
Chris@102
|
64 struct attribute_of<x3::alternative<Left, Right>, Context>
|
Chris@102
|
65 : x3::detail::attribute_of_alternative<Left, Right, Context> {};
|
Chris@102
|
66 }}}}
|
Chris@102
|
67
|
Chris@102
|
68 #endif
|