Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/spirit/home/x3/operator/alternative.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*=============================================================================
0002     Copyright (c) 2001-2014 Joel de Guzman
0003     Copyright (c) 2017 wanghan02
0004     Copyright (c) 2024 Nana Sakisaka
0005 
0006     Distributed under the Boost Software License, Version 1.0. (See accompanying
0007     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0008 =============================================================================*/
0009 #if !defined(BOOST_SPIRIT_X3_ALTERNATIVE_JAN_07_2013_1131AM)
0010 #define BOOST_SPIRIT_X3_ALTERNATIVE_JAN_07_2013_1131AM
0011 
0012 #include <boost/spirit/home/x3/support/traits/attribute_of_binary.hpp>
0013 #include <boost/spirit/home/x3/support/expectation.hpp>
0014 #include <boost/spirit/home/x3/core/parser.hpp>
0015 #include <boost/spirit/home/x3/operator/detail/alternative.hpp>
0016 
0017 #include <boost/variant/variant_fwd.hpp>
0018 
0019 namespace boost { namespace spirit { namespace x3
0020 {
0021     template <typename Left, typename Right>
0022     struct alternative : binary_parser<Left, Right, alternative<Left, Right>>
0023     {
0024         typedef binary_parser<Left, Right, alternative<Left, Right>> base_type;
0025 
0026         constexpr alternative(Left const& left, Right const& right)
0027             : base_type(left, right) {}
0028 
0029         template <typename Iterator, typename Context, typename RContext>
0030         bool parse(
0031             Iterator& first, Iterator const& last
0032           , Context const& context, RContext& rcontext, unused_type) const
0033         {
0034             return this->left.parse(first, last, context, rcontext, unused)
0035                 || (!has_expectation_failure(context)
0036                     && this->right.parse(first, last, context, rcontext, unused));
0037         }
0038 
0039         template <typename Iterator, typename Context
0040           , typename RContext, typename Attribute>
0041         bool parse(
0042             Iterator& first, Iterator const& last
0043           , Context const& context, RContext& rcontext, Attribute& attr) const
0044         {
0045             return detail::parse_alternative(this->left, first, last, context, rcontext, attr)
0046                 || (!has_expectation_failure(context)
0047                     && detail::parse_alternative(this->right, first, last, context, rcontext, attr));
0048         }
0049     };
0050 
0051     template <typename Left, typename Right>
0052     constexpr alternative<
0053         typename extension::as_parser<Left>::value_type
0054       , typename extension::as_parser<Right>::value_type>
0055     operator|(Left const& left, Right const& right)
0056     {
0057         return { as_parser(left), as_parser(right) };
0058     }
0059 }}}
0060 
0061 namespace boost { namespace spirit { namespace x3 { namespace traits
0062 {
0063     template <typename Left, typename Right, typename Context>
0064     struct attribute_of<x3::alternative<Left, Right>, Context>
0065         : x3::detail::attribute_of_binary<boost::variant, x3::alternative, Left, Right, Context> {};
0066 }}}}
0067 
0068 #endif