|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r58044 - in branches/quickbook-1.5-spirit2: . detail
From: daniel_james_at_[hidden]
Date: 2009-11-29 17:52:13
Author: danieljames
Date: 2009-11-29 17:52:12 EST (Sun, 29 Nov 2009)
New Revision: 58044
URL: http://svn.boost.org/trac/boost/changeset/58044
Log:
Use the pimpl idiom for the grammars.
Text files modified:
branches/quickbook-1.5-spirit2/block.hpp | 38 +++++++++++-
branches/quickbook-1.5-spirit2/code_snippet.hpp | 56 +++++++++++++++++-
branches/quickbook-1.5-spirit2/detail/actions.cpp | 8 +
branches/quickbook-1.5-spirit2/doc_info.hpp | 31 +++++++++
branches/quickbook-1.5-spirit2/grammars.hpp | 121 ++++++++++++++++-----------------------
branches/quickbook-1.5-spirit2/phrase.hpp | 64 +++++++++++++++++++-
6 files changed, 228 insertions(+), 90 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-29 17:52:12 EST (Sun, 29 Nov 2009)
@@ -28,11 +28,41 @@
namespace ph = boost::phoenix;
template <typename Iterator, typename Actions, bool skip_initial_spaces>
+ struct block_grammar<Iterator, Actions, skip_initial_spaces>::rules
+ {
+ rules(Actions& actions_);
+
+ Actions& actions;
+ bool no_eols;
+ phrase_grammar<Iterator, Actions> common;
+ qi::symbols<> paragraph_end_markups;
+ qi::rule<Iterator>
+ start_, blocks, block_markup, code, code_line,
+ paragraph, space, blank, comment, headings, h, h1, h2,
+ h3, h4, h5, h6, hr, blurb, blockquote, admonition,
+ phrase, list, phrase_end, ordered_list, def_macro,
+ macro_identifier, table, table_row, variablelist,
+ varlistentry, varlistterm, varlistitem, table_cell,
+ preformatted, list_item, begin_section, end_section,
+ xinclude, include, hard_space, eol, paragraph_end,
+ template_, template_id, template_formal_arg,
+ template_body, identifier, dummy_block, import,
+ inside_paragraph;
+ qi::rule<Iterator, boost::optional<std::string>()> element_id, element_id_1_5;
+ };
+
+ template <typename Iterator, typename Actions, bool skip_initial_spaces>
block_grammar<Iterator, Actions, skip_initial_spaces>::block_grammar(Actions& actions_)
- : block_grammar::base_type(start_, "block")
- , actions(actions_)
- , no_eols(true)
- , common(actions, no_eols)
+ : block_grammar::base_type(start, "block")
+ , rules_pimpl(new rules(actions_))
+ , start(rules_pimpl->start_) {}
+
+ template <typename Iterator, typename Actions, bool skip_initial_spaces>
+ block_grammar<Iterator, Actions, skip_initial_spaces>::~block_grammar() {}
+
+ template <typename Iterator, typename Actions, bool skip_initial_spaces>
+ block_grammar<Iterator, Actions, skip_initial_spaces>::rules::rules(Actions& actions_)
+ : actions(actions_), no_eols(true), common(actions, no_eols)
{
if (skip_initial_spaces)
{
Modified: branches/quickbook-1.5-spirit2/code_snippet.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/code_snippet.hpp (original)
+++ branches/quickbook-1.5-spirit2/code_snippet.hpp 2009-11-29 17:52:12 EST (Sun, 29 Nov 2009)
@@ -23,9 +23,33 @@
namespace ph = boost::phoenix;
template <typename Iterator>
+ struct python_code_snippet_grammar<Iterator>::rules
+ {
+ typedef code_snippet_actions actions_type;
+
+ rules(actions_type & actions);
+
+ actions_type& actions;
+
+ qi::rule<Iterator>
+ start_, snippet, code_elements, escaped_comment,
+ inline_callout, line_callout, ignore;
+ qi::rule<Iterator, std::string()>
+ identifier;
+ };
+
+ template <typename Iterator>
python_code_snippet_grammar<Iterator>::python_code_snippet_grammar(actions_type & actions)
- : python_code_snippet_grammar::base_type(start_)
- , actions(actions)
+ : python_code_snippet_grammar::base_type(start)
+ , rules_pimpl(new rules(actions))
+ , start(rules_pimpl->start_) {}
+
+ template <typename Iterator>
+ python_code_snippet_grammar<Iterator>::~python_code_snippet_grammar() {}
+
+ template <typename Iterator>
+ python_code_snippet_grammar<Iterator>::rules::rules(actions_type& actions)
+ : actions(actions)
{
start_ =
+(
@@ -75,9 +99,33 @@
}
template <typename Iterator>
+ struct cpp_code_snippet_grammar<Iterator>::rules
+ {
+ typedef code_snippet_actions actions_type;
+
+ rules(actions_type & actions);
+
+ actions_type& actions;
+
+ qi::rule<Iterator>
+ start_, snippet, code_elements, escaped_comment,
+ inline_callout, line_callout, ignore;
+ qi::rule<Iterator, std::string()>
+ identifier;
+ };
+
+ template <typename Iterator>
cpp_code_snippet_grammar<Iterator>::cpp_code_snippet_grammar(actions_type & actions)
- : cpp_code_snippet_grammar::base_type(start_)
- , actions(actions)
+ : cpp_code_snippet_grammar::base_type(start)
+ , rules_pimpl(new rules(actions))
+ , start(rules_pimpl->start_) {}
+
+ template <typename Iterator>
+ cpp_code_snippet_grammar<Iterator>::~cpp_code_snippet_grammar() {}
+
+ template <typename Iterator>
+ cpp_code_snippet_grammar<Iterator>::rules::rules(actions_type & actions)
+ : actions(actions)
{
start_ =
+(
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-29 17:52:12 EST (Sun, 29 Nov 2009)
@@ -692,9 +692,6 @@
, quickbook::actions& actions
)
{
- simple_phrase_grammar<iterator, quickbook::actions> phrase_p(actions);
- block_grammar<iterator, quickbook::actions, false> block_p(actions);
-
// How do we know if we are to parse the template as a block or
// a phrase? We apply a simple heuristic: if the body starts with
// a newline, then we regard it as a block, otherwise, we parse
@@ -715,6 +712,8 @@
}
else if (!is_block)
{
+ simple_phrase_grammar<iterator, quickbook::actions> phrase_p(actions);
+
// do a phrase level parse
iterator first(body.begin(), body.end(), actions.filename.native_file_string().c_str());
first.set_position(template_pos);
@@ -724,6 +723,8 @@
}
else
{
+ block_grammar<iterator, quickbook::actions, false> block_p(actions);
+
// do a block level parse
// ensure that we have enough trailing newlines to eliminate
// the need to check for end of file in the grammar.
@@ -810,6 +811,7 @@
{
detail::outerr(pos.file,pos.line)
//<< "Expanding template:" << template_info[0] << std::endl
+ << std::endl
<< "------------------begin------------------" << std::endl
<< body
<< "------------------end--------------------" << std::endl
Modified: branches/quickbook-1.5-spirit2/doc_info.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/doc_info.hpp (original)
+++ branches/quickbook-1.5-spirit2/doc_info.hpp 2009-11-29 17:52:12 EST (Sun, 29 Nov 2009)
@@ -27,9 +27,36 @@
namespace ph = boost::phoenix;
template <typename Iterator, typename Actions>
+ struct doc_info_grammar<Iterator, Actions>::rules
+ {
+ rules(Actions& actions);
+
+ Actions& actions;
+ bool unused;
+ std::pair<std::string, std::string> name;
+ std::pair<std::vector<std::string>, std::string> copyright;
+ phrase_grammar<Iterator, Actions> common;
+ qi::symbols<char> doc_types;
+ qi::rule<Iterator>
+ doc_info, doc_title, doc_version, doc_id, doc_dirname,
+ doc_copyright, doc_purpose,doc_category, doc_authors,
+ doc_author, comment, space, hard_space, doc_license,
+ doc_last_revision, doc_source_mode, phrase, quickbook_version;
+ };
+
+ template <typename Iterator, typename Actions>
doc_info_grammar<Iterator, Actions>::doc_info_grammar(Actions& actions)
- : doc_info_grammar::base_type(doc_info), actions(actions)
- , unused(false), common(actions, unused)
+ : doc_info_grammar::base_type(start)
+ , rules_pimpl(new rules(actions))
+ , start(rules_pimpl->doc_info) {}
+
+ template <typename Iterator, typename Actions>
+ doc_info_grammar<Iterator, Actions>::~doc_info_grammar() {}
+
+
+ template <typename Iterator, typename Actions>
+ doc_info_grammar<Iterator, Actions>::rules::rules(Actions& actions)
+ : actions(actions), unused(false), common(actions, unused)
{
typedef qi::uint_parser<int, 10, 1, 2> uint2_t;
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-29 17:52:12 EST (Sun, 29 Nov 2009)
@@ -12,6 +12,7 @@
#include <boost/spirit/include/qi_core.hpp>
#include <boost/spirit/include/qi_symbols.hpp>
+#include <boost/scoped_ptr.hpp>
namespace quickbook
{
@@ -21,81 +22,59 @@
struct phrase_grammar : qi::grammar<Iterator>
{
phrase_grammar(Actions& actions, bool& no_eols);
+ ~phrase_grammar();
- Actions& actions;
- bool& no_eols;
-
- qi::rule<Iterator>
- space, blank, comment, phrase, phrase_markup, image,
- phrase_end, bold, italic, underline, teletype,
- strikethrough, escape, url, common, funcref, classref,
- memberref, enumref, macroref, headerref, conceptref, globalref,
- anchor, link, hard_space, eol, inline_code, simple_format,
- simple_bold, simple_italic, simple_underline,
- simple_teletype, source_mode, template_,
- quote, code_block, footnote, replaceable, macro,
- dummy_block, cond_phrase, macro_identifier,
- brackets_1_4, template_inner_arg_1_5, brackets_1_5
- ;
-
- qi::rule<Iterator, std::string()> image_filename, template_arg_1_4, template_arg_1_5;
- qi::rule<Iterator, std::vector<std::string>() > template_args;
+ struct rules;
+ boost::scoped_ptr<rules> rules_pimpl;
+ qi::rule<Iterator> start;
+ private:
+ phrase_grammar(phrase_grammar const&);
+ phrase_grammar& operator=(phrase_grammar const&);
};
template <typename Iterator, typename Actions>
struct simple_phrase_grammar : qi::grammar<Iterator>
{
simple_phrase_grammar(Actions& actions);
+ ~simple_phrase_grammar();
- Actions& actions;
- bool unused;
- phrase_grammar<Iterator, Actions> common;
- qi::rule<Iterator> phrase, comment, dummy_block;
+ struct rules;
+ boost::scoped_ptr<rules> rules_pimpl;
+ qi::rule<Iterator> start;
+ private:
+ simple_phrase_grammar(simple_phrase_grammar const&);
+ simple_phrase_grammar& operator=(simple_phrase_grammar const&);
};
template <typename Iterator, typename Actions, bool skip_initial_spaces = false>
struct block_grammar : qi::grammar<Iterator>
{
- block_grammar(Actions& actions_);
+ block_grammar(Actions& actions);
+ ~block_grammar();
- Actions& actions;
- bool no_eols;
- phrase_grammar<Iterator, Actions> common;
- qi::symbols<> paragraph_end_markups;
- qi::rule<Iterator>
- start_, blocks, block_markup, code, code_line,
- paragraph, space, blank, comment, headings, h, h1, h2,
- h3, h4, h5, h6, hr, blurb, blockquote, admonition,
- phrase, list, phrase_end, ordered_list, def_macro,
- macro_identifier, table, table_row, variablelist,
- varlistentry, varlistterm, varlistitem, table_cell,
- preformatted, list_item, begin_section, end_section,
- xinclude, include, hard_space, eol, paragraph_end,
- template_, template_id, template_formal_arg,
- template_body, identifier, dummy_block, import,
- inside_paragraph;
- qi::rule<Iterator, boost::optional<std::string>()> element_id, element_id_1_5;
+ struct rules;
+ boost::scoped_ptr<rules> rules_pimpl;
+ qi::rule<Iterator> start;
+ private:
+ block_grammar(block_grammar const&);
+ block_grammar& operator=(block_grammar const&);
};
template <typename Iterator, typename Actions>
struct doc_info_grammar : qi::grammar<Iterator>
{
doc_info_grammar(Actions& actions);
+ ~doc_info_grammar();
- Actions& actions;
- bool unused;
- std::pair<std::string, std::string> name;
- std::pair<std::vector<std::string>, std::string> copyright;
- phrase_grammar<Iterator, Actions> common;
- qi::symbols<char> doc_types;
- qi::rule<Iterator>
- doc_info, doc_title, doc_version, doc_id, doc_dirname,
- doc_copyright, doc_purpose,doc_category, doc_authors,
- doc_author, comment, space, hard_space, doc_license,
- doc_last_revision, doc_source_mode, phrase, quickbook_version;
+ struct rules;
+ boost::scoped_ptr<rules> rules_pimpl;
+ qi::rule<Iterator> start;
+ private:
+ doc_info_grammar(doc_info_grammar const&);
+ doc_info_grammar& operator=(doc_info_grammar const&);
};
- // TODO: Duplicate definition:
+ // TODO: Duplicate declaration:
struct code_snippet_actions;
@@ -104,33 +83,33 @@
: qi::grammar<Iterator>
{
typedef code_snippet_actions actions_type;
-
- python_code_snippet_grammar(actions_type & actions);
-
- actions_type& actions;
+
+ python_code_snippet_grammar(actions_type& actions);
+ ~python_code_snippet_grammar();
- qi::rule<Iterator>
- start_, snippet, code_elements, escaped_comment,
- inline_callout, line_callout, ignore;
- qi::rule<Iterator, std::string()>
- identifier;
- };
+ struct rules;
+ boost::scoped_ptr<rules> rules_pimpl;
+ qi::rule<Iterator> start;
+ private:
+ python_code_snippet_grammar(python_code_snippet_grammar const&);
+ python_code_snippet_grammar& operator=(python_code_snippet_grammar const&);
+ };
template <typename Iterator>
struct cpp_code_snippet_grammar
: qi::grammar<Iterator>
{
typedef code_snippet_actions actions_type;
-
- cpp_code_snippet_grammar(actions_type & actions);
-
- actions_type& actions;
+
+ cpp_code_snippet_grammar(actions_type& actions);
+ ~cpp_code_snippet_grammar();
- qi::rule<Iterator>
- start_, snippet, code_elements, escaped_comment,
- inline_callout, line_callout, ignore;
- qi::rule<Iterator, std::string()>
- identifier;
+ struct rules;
+ boost::scoped_ptr<rules> rules_pimpl;
+ qi::rule<Iterator> start;
+ private:
+ cpp_code_snippet_grammar(cpp_code_snippet_grammar const&);
+ cpp_code_snippet_grammar& operator=(cpp_code_snippet_grammar const&);
};
}
Modified: branches/quickbook-1.5-spirit2/phrase.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/phrase.hpp (original)
+++ branches/quickbook-1.5-spirit2/phrase.hpp 2009-11-29 17:52:12 EST (Sun, 29 Nov 2009)
@@ -64,10 +64,44 @@
}
template <typename Iterator, typename Actions>
+ struct phrase_grammar<Iterator, Actions>::rules
+ {
+ rules(Actions& actions, bool& no_eols);
+
+ Actions& actions;
+ bool& no_eols;
+
+ qi::rule<Iterator>
+ space, blank, comment, phrase, phrase_markup, image,
+ phrase_end, bold, italic, underline, teletype,
+ strikethrough, escape, url, common, funcref, classref,
+ memberref, enumref, macroref, headerref, conceptref, globalref,
+ anchor, link, hard_space, eol, inline_code, simple_format,
+ simple_bold, simple_italic, simple_underline,
+ simple_teletype, source_mode, template_,
+ quote, code_block, footnote, replaceable, macro,
+ dummy_block, cond_phrase, macro_identifier,
+ brackets_1_4, template_inner_arg_1_5, brackets_1_5
+ ;
+
+ qi::rule<Iterator, std::string()> image_filename, template_arg_1_4, template_arg_1_5;
+ qi::rule<Iterator, std::vector<std::string>() > template_args;
+ };
+
+ template <typename Iterator, typename Actions>
phrase_grammar<Iterator, Actions>::phrase_grammar(Actions& actions, bool& no_eols)
- : phrase_grammar::base_type(common, "phrase"),
- actions(actions),
- no_eols(no_eols)
+ : phrase_grammar::base_type(start, "phrase")
+ , rules_pimpl(new rules(actions, no_eols))
+ {
+ start = rules_pimpl->common;
+ }
+
+ template <typename Iterator, typename Actions>
+ phrase_grammar<Iterator, Actions>::~phrase_grammar() {}
+
+ template <typename Iterator, typename Actions>
+ phrase_grammar<Iterator, Actions>::rules::rules(Actions& actions, bool& no_eols)
+ : actions(actions), no_eols(no_eols)
{
space =
*(qi::space | comment)
@@ -436,10 +470,28 @@
}
template <typename Iterator, typename Actions>
+ struct simple_phrase_grammar<Iterator, Actions>::rules
+ {
+ rules(Actions& actions);
+
+ Actions& actions;
+ bool unused;
+ phrase_grammar<Iterator, Actions> common;
+ qi::rule<Iterator> phrase, comment, dummy_block;
+ };
+
+ template <typename Iterator, typename Actions>
simple_phrase_grammar<Iterator, Actions>::simple_phrase_grammar(Actions& actions)
- : simple_phrase_grammar::base_type(phrase, "simple_phrase")
- , actions(actions), unused(false), common(actions, unused),
- phrase("phrase"), comment("comment"), dummy_block("dummy_block")
+ : simple_phrase_grammar::base_type(start, "simple_phrase")
+ , rules_pimpl(new rules(actions))
+ , start(rules_pimpl->phrase) {}
+
+ template <typename Iterator, typename Actions>
+ simple_phrase_grammar<Iterator, Actions>::~simple_phrase_grammar() {}
+
+ template <typename Iterator, typename Actions>
+ simple_phrase_grammar<Iterator, Actions>::rules::rules(Actions& actions)
+ : actions(actions), unused(false), common(actions, unused)
{
phrase =
*( common
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