1 /*=============================================================================
2 Copyright (c) 2001-2015 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__ANNOTATE_ON_SUCCESS_HPP)
8 #define BOOST_SPIRIT_X3__ANNOTATE_ON_SUCCESS_HPP
10 #include <boost/spirit/home/x3/support/ast/variant.hpp>
11 #include <boost/spirit/home/x3/support/context.hpp>
12 #include <boost/spirit/home/x3/support/utility/error_reporting.hpp>
13 #include <boost/spirit/home/x3/support/utility/lambda_visitor.hpp>
15 namespace boost { namespace spirit { namespace x3
17 ///////////////////////////////////////////////////////////////////////////
18 // The on_success handler tags the AST with the iterator position
19 // for error handling.
21 // The on_success handler also ties the AST to a vector of iterator
22 // positions for the purpose of subsequent semantic error handling
23 // when the program is being compiled. See x3::position_cache in
26 // We'll ask the X3's error_handler utility to do these.
27 ///////////////////////////////////////////////////////////////////////////
29 struct annotate_on_success
31 template <typename Iterator, typename Context, typename... Types>
32 inline void on_success(Iterator const& first, Iterator const& last
33 , variant<Types...>& ast, Context const& context)
35 ast.apply_visitor(x3::make_lambda_visitor<void>([&](auto& node)
37 this->on_success(first, last, node, context);
41 template <typename T, typename Iterator, typename Context>
42 inline void on_success(Iterator const& first, Iterator const& last
43 , T& ast, Context const& context)
45 auto& error_handler = get<error_handler_tag>(context).get();
46 error_handler.tag(ast, first, last);