1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 =============================================================================*/
7 #if !defined(SPIRIT_EXPECT_FUNCTION_APR_29_2007_0558PM)
8 #define SPIRIT_EXPECT_FUNCTION_APR_29_2007_0558PM
14 #include <boost/spirit/home/support/unused.hpp>
15 #include <boost/spirit/home/support/multi_pass_wrapper.hpp>
16 #include <boost/throw_exception.hpp>
18 namespace boost { namespace spirit { namespace qi { namespace detail
21 typename Iterator, typename Context
22 , typename Skipper, typename Exception>
23 struct expect_function
25 typedef Iterator iterator_type;
26 typedef Context context_type;
29 Iterator& first_, Iterator const& last_
30 , Context& context_, Skipper const& skipper_)
39 template <typename Component, typename Attribute>
40 bool operator()(Component const& component, Attribute& attr) const
42 // if this is not the first component in the expect chain we
43 // need to flush any multi_pass iterator we might be acting on
45 spirit::traits::clear_queue(first);
47 // if we are testing the first component in the sequence,
48 // return true if the parser fails, if this is not the first
49 // component, throw exception if the parser fails
50 if (!component.parse(first, last, context, skipper, attr))
55 return true; // true means the match failed
57 boost::throw_exception(Exception(first, last, component.what(context)));
58 #if defined(BOOST_NO_EXCEPTIONS)
59 return true; // for systems not supporting exceptions
66 template <typename Component>
67 bool operator()(Component const& component) const
69 // if this is not the first component in the expect chain we
70 // need to flush any multi_pass iterator we might be acting on
72 spirit::traits::clear_queue(first);
74 // if we are testing the first component in the sequence,
75 // return true if the parser fails, if this not the first
76 // component, throw exception if the parser fails
77 if (!component.parse(first, last, context, skipper, unused))
84 boost::throw_exception(Exception(first, last, component.what(context)));
85 #if defined(BOOST_NO_EXCEPTIONS)
86 return false; // for systems not supporting exceptions
96 Skipper const& skipper;
97 mutable bool is_first;
100 // silence MSVC warning C4512: assignment operator could not be generated
101 expect_function& operator= (expect_function const&);