1 /*=============================================================================
2 Copyright (c) 2001-2011 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_CALC8_ERROR_HANDLER_HPP)
8 #define BOOST_SPIRIT_CALC8_ERROR_HANDLER_HPP
16 ///////////////////////////////////////////////////////////////////////////////
18 ///////////////////////////////////////////////////////////////////////////////
19 template <typename Iterator>
22 template <typename, typename, typename>
23 struct result { typedef void type; };
25 error_handler(Iterator first, Iterator last)
26 : first(first), last(last) {}
28 template <typename Message, typename What>
30 Message const& message,
32 Iterator err_pos) const
35 Iterator line_start = get_pos(err_pos, line);
38 std::cout << message << what << " line " << line << ':' << std::endl;
39 std::cout << get_line(line_start) << std::endl;
40 for (; line_start != err_pos; ++line_start)
42 std::cout << '^' << std::endl;
46 std::cout << "Unexpected end of file. ";
47 std::cout << message << what << " line " << line << std::endl;
51 Iterator get_pos(Iterator err_pos, int& line) const
55 Iterator line_start = first;
59 if (i != err_pos && *i == '\r') // CR
64 if (i != err_pos && *i == '\n') // LF
77 std::string get_line(Iterator err_pos) const
80 // position i to the next EOL
81 while (i != last && (*i != '\r' && *i != '\n'))
83 return std::string(err_pos, i);
88 std::vector<Iterator> iters;