3 #include <boost/variant/static_visitor.hpp>
5 #include "render_context.hpp"
6 #include "mstch/mstch.hpp"
8 #include "render_node.hpp"
12 class render_section: public boost::static_visitor<std::string> {
14 enum class flag { none, keep_array };
17 const template_type& section,
18 const delim_type& delims,
19 flag p_flag = flag::none):
20 m_ctx(ctx), m_section(section), m_delims(delims), m_flag(p_flag)
25 std::string operator()(const T& t) const {
26 return render_context::push(m_ctx, t).render(m_section);
29 std::string operator()(const lambda& fun) const {
30 std::string section_str;
31 for (auto& token: m_section)
32 section_str += token.raw();
33 template_type interpreted{fun([this](const mstch::node& n) {
34 return visit(render_node(m_ctx), n);
35 }, section_str), m_delims};
36 return render_context::push(m_ctx).render(interpreted);
39 std::string operator()(const array& array) const {
41 if (m_flag == flag::keep_array)
42 return render_context::push(m_ctx, array).render(m_section);
44 for (auto& item: array)
45 out += visit(render_section(
46 m_ctx, m_section, m_delims, flag::keep_array), item);
51 render_context& m_ctx;
52 const template_type& m_section;
53 const delim_type& m_delims;