Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Copyright (c) 2001-2011 Joel de Guzman
|
Chris@16
|
3
|
Chris@16
|
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 =============================================================================*/
|
Chris@16
|
7 #if !defined(SPIRIT_EXPECT_FUNCTION_APR_29_2007_0558PM)
|
Chris@16
|
8 #define SPIRIT_EXPECT_FUNCTION_APR_29_2007_0558PM
|
Chris@16
|
9
|
Chris@16
|
10 #if defined(_MSC_VER)
|
Chris@16
|
11 #pragma once
|
Chris@16
|
12 #endif
|
Chris@16
|
13
|
Chris@16
|
14 #include <boost/spirit/home/support/unused.hpp>
|
Chris@16
|
15 #include <boost/spirit/home/support/multi_pass_wrapper.hpp>
|
Chris@16
|
16 #include <boost/throw_exception.hpp>
|
Chris@16
|
17
|
Chris@16
|
18 namespace boost { namespace spirit { namespace qi { namespace detail
|
Chris@16
|
19 {
|
Chris@16
|
20 template <
|
Chris@16
|
21 typename Iterator, typename Context
|
Chris@16
|
22 , typename Skipper, typename Exception>
|
Chris@16
|
23 struct expect_function
|
Chris@16
|
24 {
|
Chris@16
|
25 typedef Iterator iterator_type;
|
Chris@16
|
26 typedef Context context_type;
|
Chris@16
|
27
|
Chris@16
|
28 expect_function(
|
Chris@16
|
29 Iterator& first_, Iterator const& last_
|
Chris@16
|
30 , Context& context_, Skipper const& skipper_)
|
Chris@16
|
31 : first(first_)
|
Chris@16
|
32 , last(last_)
|
Chris@16
|
33 , context(context_)
|
Chris@16
|
34 , skipper(skipper_)
|
Chris@16
|
35 , is_first(true)
|
Chris@16
|
36 {
|
Chris@16
|
37 }
|
Chris@16
|
38
|
Chris@16
|
39 template <typename Component, typename Attribute>
|
Chris@16
|
40 bool operator()(Component const& component, Attribute& attr) const
|
Chris@16
|
41 {
|
Chris@16
|
42 // if this is not the first component in the expect chain we
|
Chris@16
|
43 // need to flush any multi_pass iterator we might be acting on
|
Chris@16
|
44 if (!is_first)
|
Chris@16
|
45 spirit::traits::clear_queue(first);
|
Chris@16
|
46
|
Chris@16
|
47 // if we are testing the first component in the sequence,
|
Chris@16
|
48 // return true if the parser fails, if this is not the first
|
Chris@16
|
49 // component, throw exception if the parser fails
|
Chris@16
|
50 if (!component.parse(first, last, context, skipper, attr))
|
Chris@16
|
51 {
|
Chris@16
|
52 if (is_first)
|
Chris@16
|
53 {
|
Chris@16
|
54 is_first = false;
|
Chris@16
|
55 return true; // true means the match failed
|
Chris@16
|
56 }
|
Chris@16
|
57 boost::throw_exception(Exception(first, last, component.what(context)));
|
Chris@16
|
58 #if defined(BOOST_NO_EXCEPTIONS)
|
Chris@16
|
59 return true; // for systems not supporting exceptions
|
Chris@16
|
60 #endif
|
Chris@16
|
61 }
|
Chris@16
|
62 is_first = false;
|
Chris@16
|
63 return false;
|
Chris@16
|
64 }
|
Chris@16
|
65
|
Chris@16
|
66 template <typename Component>
|
Chris@16
|
67 bool operator()(Component const& component) const
|
Chris@16
|
68 {
|
Chris@16
|
69 // if this is not the first component in the expect chain we
|
Chris@16
|
70 // need to flush any multi_pass iterator we might be acting on
|
Chris@16
|
71 if (!is_first)
|
Chris@16
|
72 spirit::traits::clear_queue(first);
|
Chris@16
|
73
|
Chris@16
|
74 // if we are testing the first component in the sequence,
|
Chris@16
|
75 // return true if the parser fails, if this not the first
|
Chris@16
|
76 // component, throw exception if the parser fails
|
Chris@16
|
77 if (!component.parse(first, last, context, skipper, unused))
|
Chris@16
|
78 {
|
Chris@16
|
79 if (is_first)
|
Chris@16
|
80 {
|
Chris@16
|
81 is_first = false;
|
Chris@16
|
82 return true;
|
Chris@16
|
83 }
|
Chris@16
|
84 boost::throw_exception(Exception(first, last, component.what(context)));
|
Chris@16
|
85 #if defined(BOOST_NO_EXCEPTIONS)
|
Chris@16
|
86 return false; // for systems not supporting exceptions
|
Chris@16
|
87 #endif
|
Chris@16
|
88 }
|
Chris@16
|
89 is_first = false;
|
Chris@16
|
90 return false;
|
Chris@16
|
91 }
|
Chris@16
|
92
|
Chris@16
|
93 Iterator& first;
|
Chris@16
|
94 Iterator const& last;
|
Chris@16
|
95 Context& context;
|
Chris@16
|
96 Skipper const& skipper;
|
Chris@16
|
97 mutable bool is_first;
|
Chris@16
|
98
|
Chris@16
|
99 private:
|
Chris@16
|
100 // silence MSVC warning C4512: assignment operator could not be generated
|
Chris@16
|
101 expect_function& operator= (expect_function const&);
|
Chris@16
|
102 };
|
Chris@16
|
103 }}}}
|
Chris@16
|
104
|
Chris@16
|
105 #endif
|