Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:47:44

0001 /*=============================================================================
0002     Copyright (c) 2001-2011 Joel de Guzman
0003 
0004     Distributed under the Boost Software License, Version 1.0. (See accompanying
0005     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 =============================================================================*/
0007 #ifndef BOOST_SPIRIT_QI_DETAIL_EXPECT_FUNCTION_HPP
0008 #define BOOST_SPIRIT_QI_DETAIL_EXPECT_FUNCTION_HPP
0009 
0010 #if defined(_MSC_VER)
0011 #pragma once
0012 #endif
0013 
0014 #include <boost/spirit/home/support/unused.hpp>
0015 #include <boost/spirit/home/support/multi_pass_wrapper.hpp>
0016 #include <boost/throw_exception.hpp>
0017 
0018 namespace boost { namespace spirit { namespace qi { namespace detail
0019 {
0020 #ifdef _MSC_VER
0021 #  pragma warning(push)
0022 #  pragma warning(disable: 4512) // assignment operator could not be generated.
0023 #endif
0024     template <
0025         typename Iterator, typename Context
0026       , typename Skipper, typename Exception>
0027     struct expect_function
0028     {
0029         typedef Iterator iterator_type;
0030         typedef Context context_type;
0031 
0032         expect_function(
0033             Iterator& first_, Iterator const& last_
0034           , Context& context_, Skipper const& skipper_)
0035           : first(first_)
0036           , last(last_)
0037           , context(context_)
0038           , skipper(skipper_)
0039           , is_first(true)
0040         {
0041         }
0042 
0043         template <typename Component, typename Attribute>
0044         bool operator()(Component const& component, Attribute& attr) const
0045         {
0046             // if this is not the first component in the expect chain we 
0047             // need to flush any multi_pass iterator we might be acting on
0048             if (!is_first)
0049                 spirit::traits::clear_queue(first);
0050 
0051             // if we are testing the first component in the sequence,
0052             // return true if the parser fails, if this is not the first
0053             // component, throw exception if the parser fails
0054             if (!component.parse(first, last, context, skipper, attr))
0055             {
0056                 if (is_first)
0057                 {
0058                     is_first = false;
0059                     return true;        // true means the match failed
0060                 }
0061                 boost::throw_exception(Exception(first, last, component.what(context)));
0062 #if defined(BOOST_NO_EXCEPTIONS)
0063                 return true;            // for systems not supporting exceptions
0064 #endif
0065             }
0066             is_first = false;
0067             return false;
0068         }
0069 
0070         template <typename Component>
0071         bool operator()(Component const& component) const
0072         {
0073             // if this is not the first component in the expect chain we 
0074             // need to flush any multi_pass iterator we might be acting on
0075             if (!is_first)
0076                 spirit::traits::clear_queue(first);
0077 
0078             // if we are testing the first component in the sequence,
0079             // return true if the parser fails, if this not the first
0080             // component, throw exception if the parser fails
0081             if (!component.parse(first, last, context, skipper, unused))
0082             {
0083                 if (is_first)
0084                 {
0085                     is_first = false;
0086                     return true;
0087                 }
0088                 boost::throw_exception(Exception(first, last, component.what(context)));
0089 #if defined(BOOST_NO_EXCEPTIONS)
0090                 return false;   // for systems not supporting exceptions
0091 #endif
0092             }
0093             is_first = false;
0094             return false;
0095         }
0096 
0097         Iterator& first;
0098         Iterator const& last;
0099         Context& context;
0100         Skipper const& skipper;
0101         mutable bool is_first;
0102     };
0103 #ifdef _MSC_VER
0104 #  pragma warning(pop)
0105 #endif
0106 }}}}
0107 
0108 #endif