]> Creatis software - cpPlugins.git/blob - lib/mstch/state/in_section.cpp
Moved to version 1.0
[cpPlugins.git] / lib / mstch / state / in_section.cpp
1 #include "in_section.hpp"
2 #include "outside_section.hpp"
3 #include "visitor/is_node_empty.hpp"
4 #include "visitor/render_section.hpp"
5
6 using namespace mstch;
7
8 in_section::in_section(type type, const token& start_token):
9     m_type(type), m_start_token(start_token), m_skipped_openings(0)
10 {
11 }
12
13 std::string in_section::render(render_context& ctx, const token& token) {
14   if (token.token_type() == token::type::section_close)
15     if (token.name() == m_start_token.name() && m_skipped_openings == 0) {
16       auto& node = ctx.get_node(m_start_token.name());
17       std::string out;
18
19       if (m_type == type::normal && !visit(is_node_empty(), node))
20         out = visit(render_section(ctx, m_section, m_start_token.delims()), node);
21       else if (m_type == type::inverted && visit(is_node_empty(), node))
22         out = render_context::push(ctx).render(m_section);
23
24       ctx.set_state<outside_section>();
25       return out;
26     } else
27       m_skipped_openings--;
28   else if (token.token_type() == token::type::inverted_section_open ||
29       token.token_type() == token::type::section_open)
30     m_skipped_openings++;
31
32   m_section << token;
33   return "";
34 }