Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-13 08:51:42

0001 /*=============================================================================
0002     Copyright (c) 2009 Chris Hoeppler
0003     Copyright (c) 2014 Lee Clagett
0004     Copyright (c) 2017 wanghan02
0005     Copyright (c) 2024 Nana Sakisaka
0006 
0007     Distributed under the Boost Software License, Version 1.0. (See accompanying
0008     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 ==============================================================================*/
0010 
0011 #if !defined(BOOST_SPIRIT_X3_CONFIX_MAY_30_2014_1819PM)
0012 #define BOOST_SPIRIT_X3_CONFIX_MAY_30_2014_1819PM
0013 
0014 #include <boost/spirit/home/x3/core/parser.hpp>
0015 #include <boost/spirit/home/x3/support/expectation.hpp>
0016 
0017 namespace boost { namespace spirit { namespace x3
0018 {
0019     template<typename Prefix, typename Subject, typename Postfix>
0020     struct confix_directive :
0021         unary_parser<Subject, confix_directive<Prefix, Subject, Postfix>>
0022     {
0023         typedef unary_parser<
0024             Subject, confix_directive<Prefix, Subject, Postfix>> base_type;
0025         static bool const is_pass_through_unary = true;
0026         static bool const handles_container = Subject::handles_container;
0027 
0028         constexpr confix_directive(Prefix const& prefix
0029                          , Subject const& subject
0030                          , Postfix const& postfix) :
0031             base_type(subject),
0032             prefix(prefix),
0033             postfix(postfix)
0034         {
0035         }
0036 
0037         template<typename Iterator, typename Context
0038                  , typename RContext, typename Attribute>
0039         bool parse(
0040             Iterator& first, Iterator const& last
0041             , Context const& context, RContext& rcontext, Attribute& attr) const
0042         {
0043             Iterator save = first;
0044 
0045             if (!(prefix.parse(first, last, context, rcontext, unused) &&
0046                   this->subject.parse(first, last, context, rcontext, attr) &&
0047                   postfix.parse(first, last, context, rcontext, unused)))
0048             {
0049             #if !BOOST_SPIRIT_X3_THROW_EXPECTATION_FAILURE
0050                 if (has_expectation_failure(context))
0051                 {
0052                     // don't rollback iterator (mimicking exception-like behavior)
0053                     return false;
0054                 }
0055             #endif
0056 
0057                 first = save;
0058                 return false;
0059             }
0060 
0061             return true;
0062         }
0063 
0064         Prefix prefix;
0065         Postfix postfix;
0066     };
0067 
0068     template<typename Prefix, typename Postfix>
0069     struct confix_gen
0070     {
0071         template<typename Subject>
0072         constexpr confix_directive<
0073             Prefix, typename extension::as_parser<Subject>::value_type, Postfix>
0074         operator[](Subject const& subject) const
0075         {
0076             return { prefix, as_parser(subject), postfix };
0077         }
0078 
0079         Prefix prefix;
0080         Postfix postfix;
0081     };
0082 
0083 
0084     template<typename Prefix, typename Postfix>
0085     constexpr confix_gen<typename extension::as_parser<Prefix>::value_type,
0086                typename extension::as_parser<Postfix>::value_type>
0087     confix(Prefix const& prefix, Postfix const& postfix)
0088     {
0089         return { as_parser(prefix), as_parser(postfix) };
0090     }
0091 
0092 }}}
0093 
0094 #endif