|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r57778 - in branches/quickbook-1.5-spirit2: . detail
From: daniel_james_at_[hidden]
Date: 2009-11-18 18:20:25
Author: danieljames
Date: 2009-11-18 18:20:23 EST (Wed, 18 Nov 2009)
New Revision: 57778
URL: http://svn.boost.org/trac/boost/changeset/57778
Log:
Use synthesized attributes for element ids.
Text files modified:
branches/quickbook-1.5-spirit2/block.hpp | 45 ++++++++++++++++-----------------------
branches/quickbook-1.5-spirit2/detail/actions.cpp | 25 +++++++++------------
branches/quickbook-1.5-spirit2/detail/actions.hpp | 24 +++++++++++++--------
branches/quickbook-1.5-spirit2/detail/actions_class.cpp | 4 --
branches/quickbook-1.5-spirit2/detail/actions_class.hpp | 2 -
branches/quickbook-1.5-spirit2/grammars.hpp | 3 +
6 files changed, 48 insertions(+), 55 deletions(-)
Modified: branches/quickbook-1.5-spirit2/block.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block.hpp (original)
+++ branches/quickbook-1.5-spirit2/block.hpp 2009-11-18 18:20:23 EST (Wed, 18 Nov 2009)
@@ -20,6 +20,7 @@
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_container.hpp>
+#include <boost/spirit/include/phoenix_bind.hpp>
namespace quickbook
{
@@ -116,32 +117,24 @@
;
element_id =
+ -(
':'
- >>
- (
- (
- qi::eps(ph::ref(qbk_version_n) >= 105u) >> space
- | qi::eps(ph::ref(qbk_version_n) < 105u)
- )
- >> qi::raw[+(qi::alnum | '_')] [ph::ref(actions.element_id) = as_string(qi::_1)]
- | qi::raw[qi::eps] [actions.element_id_warning]
- [ph::clear(ph::ref(actions.element_id))]
+ >> -(qi::eps(qbk_since(105u)) >> space)
+ >> (
+ (+(qi::alnum | qi::char_('_'))) [qi::_val = as_string(qi::_1)]
+ | qi::raw[qi::eps] [actions.element_id_warning]
)
- | qi::eps [ph::clear(ph::ref(actions.element_id))]
- ;
+ );
+
element_id_1_5 =
- qi::eps(ph::ref(qbk_version_n) >= 105u) >> element_id
- |
- qi::eps(ph::ref(qbk_version_n) < 105u)
- [ph::clear(ph::ref(actions.element_id))]
- ;
+ -(qi::eps(qbk_since(105u)) >> element_id [qi::_val = qi::_1]);
- begin_section =
+ begin_section = (
"section"
>> hard_space
>> element_id
- >> qi::raw[phrase] [actions.begin_section]
+ >> qi::raw[phrase]) [ph::bind(actions.begin_section, qi::_1, qi::_2)]
;
end_section =
@@ -243,13 +236,13 @@
>> space >> &qi::lit(']')
;
- variablelist =
+ variablelist = (
"variablelist"
- >> (&(*qi::blank >> qi::eol) | hard_space)
- >> (*(qi::char_ - eol)) [ph::ref(actions.table_title) = as_string(qi::_1)]
+ >> qi::omit[&(*qi::blank >> qi::eol) | hard_space]
+ >> *(qi::char_ - eol)
>> +eol
>> *varlistentry
- >> qi::eps [actions.variablelist]
+ ) [ph::bind(actions.variablelist, as_string(qi::_1))]
;
varlistentry =
@@ -295,15 +288,15 @@
)
;
- table =
+ table = (
"table"
>> (&(*qi::blank >> qi::eol) | hard_space)
- >> element_id_1_5
+ >> element_id_1_5
>> (&(*qi::blank >> qi::eol) | space)
- >> (*(qi::char_ - eol)) [ph::ref(actions.table_title) = as_string(qi::_1)]
+ >> *(qi::char_ - eol)
>> +eol
>> *table_row
- >> qi::eps [actions.table]
+ ) [ph::bind(actions.table, qi::_1, as_string(qi::_2))]
;
table_row =
Modified: branches/quickbook-1.5-spirit2/detail/actions.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/detail/actions.cpp (original)
+++ branches/quickbook-1.5-spirit2/detail/actions.cpp 2009-11-18 18:20:23 EST (Wed, 18 Nov 2009)
@@ -858,13 +858,13 @@
}
}
- void variablelist_action::operator()(unused_type, unused_type, unused_type) const
+ void variablelist_action::operator()(std::string const& title) const
{
actions.out << "<variablelist>\n";
actions.out << "<title>";
- std::string::iterator first = actions.table_title.begin();
- std::string::iterator last = actions.table_title.end();
+ std::string::const_iterator first = title.begin();
+ std::string::const_iterator last = title.end();
while (first != last)
detail::print_char(*first++, actions.out.get());
actions.out << "</title>\n";
@@ -876,7 +876,6 @@
actions.out << "</variablelist>\n";
actions.table_span = 0;
actions.table_header.clear();
- actions.table_title.clear();
}
void start_varlistitem_action::operator()(unused_type, unused_type, unused_type) const
@@ -893,17 +892,17 @@
phrase << str << end_varlistitem_;
}
- void table_action::operator()(unused_type, unused_type, unused_type) const
+ void table_action::operator()(boost::optional<std::string> const& id, std::string const& title) const
{
- std::string::iterator first = actions.table_title.begin();
- std::string::iterator last = actions.table_title.end();
+ std::string::const_iterator first = title.begin();
+ std::string::const_iterator last = title.end();
bool has_title = first != last;
std::string table_id;
if(qbk_version_n >= 105) {
- if(!actions.element_id.empty()) {
+ if(id) {
table_id = fully_qualified_id(actions.doc_id,
- actions.qualified_section_id, actions.element_id);
+ actions.qualified_section_id, *id);
}
else if(has_title) {
table_id = fully_qualified_id(actions.doc_id,
@@ -958,7 +957,6 @@
actions.table_span = 0;
actions.table_header.clear();
- actions.table_title.clear();
}
void start_row_action::operator()(unused_type, unused_type, unused_type) const
@@ -988,11 +986,10 @@
phrase << str << end_cell_;
}
- void begin_section_action::operator()(iterator_range x, unused_type, unused_type) const
+ void begin_section_action::operator()(boost::optional<std::string> const& id, iterator_range x) const
{
- section_id = element_id.empty() ?
- detail::make_identifier(x.begin(), x.end()) :
- element_id;
+ section_id = id ? *id :
+ detail::make_identifier(x.begin(), x.end());
if (section_level != 0)
qualified_section_id += '.';
Modified: branches/quickbook-1.5-spirit2/detail/actions.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/detail/actions.hpp (original)
+++ branches/quickbook-1.5-spirit2/detail/actions.hpp 2009-11-18 18:20:23 EST (Wed, 18 Nov 2009)
@@ -585,7 +585,10 @@
variablelist_action(quickbook::actions& actions)
: actions(actions) {}
- void operator()(unused_type, unused_type, unused_type) const;
+ template <typename T>
+ struct result { typedef void type; };
+
+ void operator()(std::string const&) const;
quickbook::actions& actions;
};
@@ -597,7 +600,10 @@
table_action(quickbook::actions& actions)
: actions(actions) {}
- void operator()(unused_type, unused_type, unused_type) const;
+ template <typename Arg1, typename Arg2>
+ struct result { typedef void type; };
+
+ void operator()(boost::optional<std::string> const&, std::string const&) const;
quickbook::actions& actions;
};
@@ -641,7 +647,7 @@
};
struct begin_section_action
- {
+ {
// Handles begin page
begin_section_action(
@@ -650,17 +656,18 @@
, std::string& library_id
, std::string& section_id
, int& section_level
- , std::string& qualified_section_id
- , std::string& element_id)
+ , std::string& qualified_section_id)
: out(out)
, phrase(phrase)
, library_id(library_id)
, section_id(section_id)
, section_level(section_level)
- , qualified_section_id(qualified_section_id)
- , element_id(element_id) {}
+ , qualified_section_id(qualified_section_id) {}
- void operator()(iterator_range, unused_type, unused_type) const;
+ template <typename A1, typename A2>
+ struct result { typedef void type; };
+
+ void operator()(boost::optional<std::string> const&, iterator_range) const;
collector& out;
collector& phrase;
@@ -668,7 +675,6 @@
std::string& section_id;
int& section_level;
std::string& qualified_section_id;
- std::string& element_id;
};
struct end_section_action
Modified: branches/quickbook-1.5-spirit2/detail/actions_class.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/detail/actions_class.cpp (original)
+++ branches/quickbook-1.5-spirit2/detail/actions_class.cpp 2009-11-18 18:20:23 EST (Wed, 18 Nov 2009)
@@ -52,8 +52,6 @@
, source_mode("c++")
// temporary or global state
- , element_id()
- , table_title()
, table_span(0)
, table_header()
, macro_id()
@@ -171,7 +169,7 @@
, end_cell(phrase, temp_para)
, anchor(out)
- , begin_section(out, phrase, doc_id, section_id, section_level, qualified_section_id, element_id)
+ , begin_section(out, phrase, doc_id, section_id, section_level, qualified_section_id)
, end_section(out, section_level, qualified_section_id, error_count)
, xinclude(out, *this)
, include(*this)
Modified: branches/quickbook-1.5-spirit2/detail/actions_class.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/detail/actions_class.hpp (original)
+++ branches/quickbook-1.5-spirit2/detail/actions_class.hpp 2009-11-18 18:20:23 EST (Wed, 18 Nov 2009)
@@ -79,8 +79,6 @@
std::stack<state_tuple> state_stack;
// temporary or global state
- std::string element_id;
- std::string table_title;
unsigned table_span;
std::string table_header;
std::string macro_id;
Modified: branches/quickbook-1.5-spirit2/grammars.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/grammars.hpp (original)
+++ branches/quickbook-1.5-spirit2/grammars.hpp 2009-11-18 18:20:23 EST (Wed, 18 Nov 2009)
@@ -74,7 +74,8 @@
xinclude, include, hard_space, eol, paragraph_end,
template_, template_id, template_formal_arg,
template_body, identifier, dummy_block, import,
- inside_paragraph, element_id, element_id_1_5;
+ inside_paragraph;
+ qi::rule<Iterator, boost::optional<std::string>()> element_id, element_id_1_5;
};
template <typename Iterator, typename Actions>
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk