1 /*============================================================================= 2 Copyright (c) 2001-2015 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__ANNOTATE_ON_SUCCESS_HPP) 8 #define BOOST_SPIRIT_X3__ANNOTATE_ON_SUCCESS_HPP 9 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> 14 15 namespace boost { namespace spirit { namespace x3 16 { 17 /////////////////////////////////////////////////////////////////////////// 18 // The on_success handler tags the AST with the iterator position 19 // for error handling. 20 // 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 24 // x3/support/ast. 25 // 26 // We'll ask the X3's error_handler utility to do these. 27 /////////////////////////////////////////////////////////////////////////// 28 29 struct annotate_on_success 30 { 31 template <typename Iterator, typename Context, typename... Types> on_successboost::spirit::x3::annotate_on_success32 inline void on_success(Iterator const& first, Iterator const& last 33 , variant<Types...>& ast, Context const& context) 34 { 35 ast.apply_visitor(x3::make_lambda_visitor<void>([&](auto& node) 36 { 37 this->on_success(first, last, node, context); 38 })); 39 } 40 41 template <typename T, typename Iterator, typename Context> on_successboost::spirit::x3::annotate_on_success42 inline void on_success(Iterator const& first, Iterator const& last 43 , T& ast, Context const& context) 44 { 45 auto& error_handler = get<error_handler_tag>(context).get(); 46 error_handler.tag(ast, first, last); 47 } 48 }; 49 }}} 50 51 #endif 52