Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:02:38

0001 /*=============================================================================
0002     Copyright (c) 2001-2015 Joel de Guzman
0003 
0004     Distributed under the Boost Software License, Version 1.0. (See accompanying
0005     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 =============================================================================*/
0007 #if !defined(BOOST_SPIRIT_X3__ANNOTATE_ON_SUCCESS_HPP)
0008 #define BOOST_SPIRIT_X3__ANNOTATE_ON_SUCCESS_HPP
0009 
0010 #include <boost/spirit/home/x3/support/ast/variant.hpp>
0011 #include <boost/spirit/home/x3/support/context.hpp>
0012 #include <boost/spirit/home/x3/support/utility/error_reporting.hpp>
0013 #include <boost/spirit/home/x3/support/utility/lambda_visitor.hpp>
0014 #include <boost/spirit/home/x3/support/traits/is_variant.hpp>
0015 
0016 namespace boost { namespace spirit { namespace x3
0017 {
0018     ///////////////////////////////////////////////////////////////////////////
0019     //  The on_success handler tags the AST with the iterator position
0020     //  for error handling.
0021     //
0022     //  The on_success handler also ties the AST to a vector of iterator
0023     //  positions for the purpose of subsequent semantic error handling
0024     //  when the program is being compiled. See x3::position_cache in
0025     //  x3/support/ast.
0026     //
0027     //  We'll ask the X3's error_handler utility to do these.
0028     ///////////////////////////////////////////////////////////////////////////
0029 
0030     struct annotate_on_success
0031     {
0032         template <typename Iterator, typename Context, typename... Types>
0033         inline void on_success(Iterator const& first, Iterator const& last
0034           , variant<Types...>& ast, Context const& context)
0035         {
0036             ast.apply_visitor(x3::make_lambda_visitor<void>([&](auto& node)
0037             {
0038                 this->on_success(first, last, node, context);
0039             }));
0040         }
0041 
0042         template <typename T, typename Iterator, typename Context>
0043         inline void on_success(Iterator const& first, Iterator const& last
0044           , forward_ast<T>& ast, Context const& context)
0045         {
0046             this->on_success(first, last, ast.get(), context);
0047         }
0048 
0049         template <typename T, typename Iterator, typename Context>
0050         inline typename disable_if<traits::is_variant<T>>::type on_success(Iterator const& first, Iterator const& last
0051           , T& ast, Context const& context)
0052         {
0053             auto& error_handler = x3::get<error_handler_tag>(context).get();
0054             error_handler.tag(ast, first, last);
0055         }
0056     };
0057 }}}
0058 
0059 #endif