diff --git a/src/state/in_inverted_section.cpp b/src/state/in_inverted_section.cpp index eeac8ba..2aef5da 100644 --- a/src/state/in_inverted_section.cpp +++ b/src/state/in_inverted_section.cpp @@ -23,10 +23,9 @@ std::string state::in_inverted_section::render( if(token.content() == section_name && skipped_openings == 0) { std::ostringstream out; auto& section_node = ctx.get_node(section_name); - if(boost::apply_visitor(visitor::is_node_empty(), section_node)) { - auto empty = mstch::object{}; - out << render_context(empty, ctx).render(section_text.str()); - } + if(boost::apply_visitor(visitor::is_node_empty(), section_node)) + out << render_context(mstch::object{}, ctx) + .render(section_text.str()); ctx.set_state(); return out.str(); } else { diff --git a/src/state/in_section.cpp b/src/state/in_section.cpp index f6848cc..11ed10c 100644 --- a/src/state/in_section.cpp +++ b/src/state/in_section.cpp @@ -20,8 +20,9 @@ std::string state::in_section::render( auto section_node = ctx.get_node(section_name); std::string out(""); if (!boost::apply_visitor(visitor::is_node_empty(), section_node)) - out = boost::apply_visitor(visitor::render_section( - ctx, section_text.str()), section_node); + out = boost::apply_visitor( + visitor::render_section(ctx, section_text.str()), + section_node); ctx.set_state(); return out; } else { diff --git a/src/visitor/render_section.cpp b/src/visitor/render_section.cpp index 94b5e8c..173a524 100644 --- a/src/visitor/render_section.cpp +++ b/src/visitor/render_section.cpp @@ -5,16 +5,19 @@ using namespace mstch; visitor::render_section::render_section( render_context& context, - const std::string& section): + const std::string& section, + std::set flags): context(context), - section(section) + section(section), + flags(flags) { } std::string visitor::render_section::operator()( const boost::blank& blank) const { - return ""; + return render_context(mstch::object{{".", mstch::node{}}}, context) + .render(section); } std::string visitor::render_section::operator()(const int& i) const { @@ -29,14 +32,17 @@ std::string visitor::render_section::operator()(const std::string& str) const { return render_context(mstch::object{{".", str}}, context).render(section); } -std::string visitor::render_section::operator()(const array& arr) const { - std::ostringstream out; - for (auto& item: arr) - out << render_context(mstch::object{{".", item}}, context) - .render(section); - return out.str(); -} - std::string visitor::render_section::operator()(const object& obj) const { return render_context(obj, context).render(section); } + +std::string visitor::render_section::operator()(const array& a) const { + std::ostringstream out; + if(flags.find(flag::keep_array) != flags.end()) + out << render_context(mstch::object{{".", a}}, context).render(section); + else + for (auto& item: a) + out << boost::apply_visitor( + render_section(context, section, {flag::keep_array}), item); + return out.str(); +} diff --git a/src/visitor/render_section.h b/src/visitor/render_section.h index f6a4cb8..2a74529 100644 --- a/src/visitor/render_section.h +++ b/src/visitor/render_section.h @@ -4,17 +4,24 @@ #include #include #include +#include #include "types.h" namespace mstch { namespace visitor { class render_section: public boost::static_visitor { + public: + enum class flag { keep_array }; private: render_context& context; std::string section; + std::set flags; public: - render_section(render_context& context, const std::string& section); + render_section( + render_context& context, + const std::string& section, + std::set flags = {}); std::string operator()(const boost::blank& blank) const; std::string operator()(const int& i) const; std::string operator()(const bool& b) const;