]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/tools/quickbook/src/template_stack.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / tools / quickbook / src / template_stack.cpp
CommitLineData
7c673cae
FG
1/*=============================================================================
2 Copyright (c) 2002 2004 2006 Joel de Guzman
3 http://spirit.sourceforge.net/
4
5 Use, modification and distribution is subject to the Boost Software
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8=============================================================================*/
9
10#include <cassert>
11#include "template_stack.hpp"
12#include "files.hpp"
13
14#ifdef BOOST_MSVC
15#pragma warning(disable : 4355)
16#endif
17
18namespace quickbook
19{
20 template_symbol::template_symbol(
b32b8144
FG
21 std::string const& identifier_,
22 std::vector<std::string> const& params_,
23 value const& content_,
24 template_scope const* lexical_parent_)
25 : identifier(identifier_)
26 , params(params_)
27 , content(content_)
28 , lexical_parent(lexical_parent_)
7c673cae
FG
29 {
30 assert(content.get_tag() == template_tags::block ||
31 content.get_tag() == template_tags::phrase ||
32 content.get_tag() == template_tags::snippet);
33 }
34
35 template_stack::template_stack()
36 : scope(template_stack::parser(*this))
37 , scopes()
38 , parent_1_4(0)
39 {
40 scopes.push_front(template_scope());
41 parent_1_4 = &scopes.front();
42 }
43
44 template_symbol* template_stack::find(std::string const& symbol) const
45 {
46 for (template_scope const* i = &*scopes.begin(); i; i = i->parent_scope)
47 {
48 if (template_symbol* ts = boost::spirit::classic::find(i->symbols, symbol.c_str()))
49 return ts;
50 }
51 return 0;
52 }
53
54 template_symbol* template_stack::find_top_scope(std::string const& symbol) const
55 {
56 return boost::spirit::classic::find(scopes.front().symbols, symbol.c_str());
57 }
58
59 template_symbols const& template_stack::top() const
60 {
61 BOOST_ASSERT(!scopes.empty());
62 return scopes.front().symbols;
63 }
64
65 template_scope const& template_stack::top_scope() const
66 {
67 BOOST_ASSERT(!scopes.empty());
68 return scopes.front();
69 }
70
71 bool template_stack::add(template_symbol const& ts)
72 {
73 BOOST_ASSERT(!scopes.empty());
74 BOOST_ASSERT(ts.lexical_parent);
75
76 if (this->find_top_scope(ts.identifier)) {
77 return false;
78 }
79
80 boost::spirit::classic::add(scopes.front().symbols,
81 ts.identifier.c_str(), ts);
82
83 return true;
84 }
85
86 void template_stack::push()
87 {
88 template_scope const& old_front = scopes.front();
89 scopes.push_front(template_scope());
90 scopes.front().parent_1_4 = parent_1_4;
91 scopes.front().parent_scope = &old_front;
92 parent_1_4 = &scopes.front();
93 }
94
95 void template_stack::pop()
96 {
97 parent_1_4 = scopes.front().parent_1_4;
98 scopes.pop_front();
99 }
100
101 void template_stack::start_template(template_symbol const* symbol)
102 {
103 // Quickbook 1.4-: When expanding the template continue to use the
104 // current scope (the dynamic scope).
105 // Quickbook 1.5+: Use the scope the template was defined in
106 // (the static scope).
107 if (symbol->content.get_file()->version() >= 105u)
108 {
109 parent_1_4 = scopes.front().parent_1_4;
110 scopes.front().parent_scope = symbol->lexical_parent;
111 }
112 else
113 {
114 scopes.front().parent_scope = scopes.front().parent_1_4;
115 }
116 }
117}
118
119