Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / spirit / example / x3 / calc8 / error_handler.hpp
1 /*=============================================================================
2     Copyright (c) 2001-2014 Joel de Guzman
3
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(BOOST_SPIRIT_X3_CALC8_ERROR_HANDLER_HPP)
8 #define BOOST_SPIRIT_X3_CALC8_ERROR_HANDLER_HPP
9
10 #include <boost/spirit/home/x3.hpp>
11 #include <boost/spirit/home/x3/support/utility/error_reporting.hpp>
12 #include <boost/spirit/home/x3/support/ast/position_tagged.hpp>
13 #include "expression.hpp"
14 #include "statement.hpp"
15
16 namespace client { namespace parser
17 {
18     namespace x3 = boost::spirit::x3;
19     
20     ////////////////////////////////////////////////////////////////////////////
21     //  Our error handler
22     ////////////////////////////////////////////////////////////////////////////
23     template <typename Iterator>
24     using error_handler = x3::error_handler<Iterator>;
25
26     // tag used to get our error handler from the context
27     struct error_handler_tag;
28     
29     struct error_handler_base
30     {
31         template <typename Iterator, typename Exception, typename Context>
32         x3::error_handler_result on_error(
33             Iterator& first, Iterator const& last
34           , Exception const& x, Context const& context)
35         {
36             std::string message = "Error! Expecting: " + x.which() + " here:";
37             auto& error_handler = x3::get<error_handler_tag>(context).get();
38             error_handler(x.where(), message);
39             return x3::error_handler_result::fail;
40         }
41     };
42 }}
43
44 #endif