• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_REPR_PRINTER_HPP)
8 #define BOOST_SPIRIT_X3_REPR_PRINTER_HPP
9 
10 #include "ast.hpp"
11 
12 #include <ostream>
13 
14 namespace rexpr { namespace ast
15 {
16     ///////////////////////////////////////////////////////////////////////////
17     //  Print out the rexpr tree
18     ///////////////////////////////////////////////////////////////////////////
19     int const tabsize = 4;
20 
21     struct rexpr_printer
22     {
23         typedef void result_type;
24 
rexpr_printerrexpr::ast::rexpr_printer25         rexpr_printer(std::ostream& out, int indent = 0)
26           : out(out), indent(indent) {}
27 
operator ()rexpr::ast::rexpr_printer28         void operator()(rexpr const& ast) const
29         {
30             out << '{' << std::endl;
31             for (auto const& entry : ast.entries)
32             {
33                 tab(indent+tabsize);
34                 out << '"' << entry.first << "\" = ";
35                 boost::apply_visitor(rexpr_printer(out, indent+tabsize), entry.second);
36             }
37             tab(indent);
38             out << '}' << std::endl;
39         }
40 
operator ()rexpr::ast::rexpr_printer41         void operator()(std::string const& text) const
42         {
43             out << '"' << text << '"' << std::endl;
44         }
45 
tabrexpr::ast::rexpr_printer46         void tab(int spaces) const
47         {
48             for (int i = 0; i < spaces; ++i)
49                 out << ' ';
50         }
51 
52         std::ostream& out;
53         int indent;
54     };
55 }}
56 
57 #endif
58