2
0
mirror of https://github.com/boostorg/spirit.git synced 2026-01-19 04:42:11 +00:00
Files
spirit/classic/example/fundamental/error_handling.cpp
Joel de Guzman 994d4e48cc moving stuff to classic spirit
[SVN r44163]
2008-04-10 23:51:31 +00:00

56 lines
1.6 KiB
C++

/*=============================================================================
Copyright (c) 1998-2003 Joel de Guzman
http://spirit.sourceforge.net/
Use, modification and distribution is subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
///////////////////////////////////////////////////////////////////////////////
//
// This sample demonstrates error handling as seen in the
// Error Handling" chapter in the User's Guide.
//
///////////////////////////////////////////////////////////////////////////////
#include <boost/spirit/include/core.hpp>
#include <boost/spirit/include/exceptions.hpp>
#include <iostream>
#include <cassert>
using namespace std;
using namespace boost::spirit;
struct handler
{
template <typename ScannerT, typename ErrorT>
error_status<>
operator()(ScannerT const& /*scan*/, ErrorT const& /*error*/) const
{
cout << "exception caught...Test concluded successfully" << endl;
return error_status<>(error_status<>::fail);
}
};
int
main()
{
cout << "/////////////////////////////////////////////////////////\n\n";
cout << "\t\tExceptions Test...\n\n";
cout << "/////////////////////////////////////////////////////////\n\n";
assertion<int> expect(0);
guard<int> my_guard;
rule<> start =
my_guard(ch_p('a') >> 'b' >> 'c' >> expect( ch_p('d') ))
[
handler()
];
bool r = parse("abcx", start).full;
assert(!r);
return 0;
}