1 /*=============================================================================
2 Copyright (c) 2001-2014 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(BOOST_SPIRIT_X3_CALC8_ERROR_HANDLER_HPP)
8 #define BOOST_SPIRIT_X3_CALC8_ERROR_HANDLER_HPP
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"
16 namespace client { namespace parser
18 namespace x3 = boost::spirit::x3;
20 ////////////////////////////////////////////////////////////////////////////
22 ////////////////////////////////////////////////////////////////////////////
23 template <typename Iterator>
24 using error_handler = x3::error_handler<Iterator>;
26 // tag used to get our error handler from the context
27 struct error_handler_tag;
29 struct error_handler_base
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)
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;