1 /*============================================================================= 2 Copyright (c) 1998-2003 Joel de Guzman 3 http://spirit.sourceforge.net/ 4 5 Use, modification and distribution is subject to the Boost Software 6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 http://www.boost.org/LICENSE_1_0.txt) 8 =============================================================================*/ 9 /////////////////////////////////////////////////////////////////////////////// 10 // 11 // This sample demonstrates error handling as seen in the 12 // Error Handling" chapter in the User's Guide. 13 // 14 /////////////////////////////////////////////////////////////////////////////// 15 #include <boost/spirit/include/classic_core.hpp> 16 #include <boost/spirit/include/classic_exceptions.hpp> 17 #include <iostream> 18 #include <boost/assert.hpp> 19 20 using namespace std; 21 using namespace BOOST_SPIRIT_CLASSIC_NS; 22 23 struct handler 24 { 25 template <typename ScannerT, typename ErrorT> 26 error_status<> operator ()handler27 operator()(ScannerT const& /*scan*/, ErrorT const& /*error*/) const 28 { 29 cout << "exception caught...Test concluded successfully" << endl; 30 return error_status<>(error_status<>::fail); 31 } 32 }; 33 34 int main()35main() 36 { 37 cout << "/////////////////////////////////////////////////////////\n\n"; 38 cout << "\t\tExceptions Test...\n\n"; 39 cout << "/////////////////////////////////////////////////////////\n\n"; 40 41 assertion<int> expect(0); 42 guard<int> my_guard; 43 44 rule<> start = 45 my_guard(ch_p('a') >> 'b' >> 'c' >> expect( ch_p('d') )) 46 [ 47 handler() 48 ]; 49 50 bool r = parse("abcx", start).full; 51 52 BOOST_ASSERT(!r); 53 return 0; 54 } 55 56