Chris@16: /*============================================================================= Chris@16: Copyright (c) 2001-2011 Joel de Guzman Chris@16: Chris@16: Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: =============================================================================*/ Chris@16: #if !defined(SPIRIT_EXPECT_FUNCTION_APR_29_2007_0558PM) Chris@16: #define SPIRIT_EXPECT_FUNCTION_APR_29_2007_0558PM Chris@16: Chris@16: #if defined(_MSC_VER) Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace spirit { namespace qi { namespace detail Chris@16: { Chris@16: template < Chris@16: typename Iterator, typename Context Chris@16: , typename Skipper, typename Exception> Chris@16: struct expect_function Chris@16: { Chris@16: typedef Iterator iterator_type; Chris@16: typedef Context context_type; Chris@16: Chris@16: expect_function( Chris@16: Iterator& first_, Iterator const& last_ Chris@16: , Context& context_, Skipper const& skipper_) Chris@16: : first(first_) Chris@16: , last(last_) Chris@16: , context(context_) Chris@16: , skipper(skipper_) Chris@16: , is_first(true) Chris@16: { Chris@16: } Chris@16: Chris@16: template Chris@16: bool operator()(Component const& component, Attribute& attr) const Chris@16: { Chris@16: // if this is not the first component in the expect chain we Chris@16: // need to flush any multi_pass iterator we might be acting on Chris@16: if (!is_first) Chris@16: spirit::traits::clear_queue(first); Chris@16: Chris@16: // if we are testing the first component in the sequence, Chris@16: // return true if the parser fails, if this is not the first Chris@16: // component, throw exception if the parser fails Chris@16: if (!component.parse(first, last, context, skipper, attr)) Chris@16: { Chris@16: if (is_first) Chris@16: { Chris@16: is_first = false; Chris@16: return true; // true means the match failed Chris@16: } Chris@16: boost::throw_exception(Exception(first, last, component.what(context))); Chris@16: #if defined(BOOST_NO_EXCEPTIONS) Chris@16: return true; // for systems not supporting exceptions Chris@16: #endif Chris@16: } Chris@16: is_first = false; Chris@16: return false; Chris@16: } Chris@16: Chris@16: template Chris@16: bool operator()(Component const& component) const Chris@16: { Chris@16: // if this is not the first component in the expect chain we Chris@16: // need to flush any multi_pass iterator we might be acting on Chris@16: if (!is_first) Chris@16: spirit::traits::clear_queue(first); Chris@16: Chris@16: // if we are testing the first component in the sequence, Chris@16: // return true if the parser fails, if this not the first Chris@16: // component, throw exception if the parser fails Chris@16: if (!component.parse(first, last, context, skipper, unused)) Chris@16: { Chris@16: if (is_first) Chris@16: { Chris@16: is_first = false; Chris@16: return true; Chris@16: } Chris@16: boost::throw_exception(Exception(first, last, component.what(context))); Chris@16: #if defined(BOOST_NO_EXCEPTIONS) Chris@16: return false; // for systems not supporting exceptions Chris@16: #endif Chris@16: } Chris@16: is_first = false; Chris@16: return false; Chris@16: } Chris@16: Chris@16: Iterator& first; Chris@16: Iterator const& last; Chris@16: Context& context; Chris@16: Skipper const& skipper; Chris@16: mutable bool is_first; Chris@16: Chris@16: private: Chris@16: // silence MSVC warning C4512: assignment operator could not be generated Chris@16: expect_function& operator= (expect_function const&); Chris@16: }; Chris@16: }}}} Chris@16: Chris@16: #endif