|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r67327 - trunk/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2010-12-19 08:29:29
Author: danieljames
Date: 2010-12-19 08:29:25 EST (Sun, 19 Dec 2010)
New Revision: 67327
URL: http://svn.boost.org/trac/boost/changeset/67327
Log:
Create a single grammar class.
Like on the spirit 2 branch, although this is a bit of an odd thing to
do with classic spirit. Still also requiring the expected scanner.
Added:
trunk/tools/quickbook/src/grammar.cpp (contents, props changed)
trunk/tools/quickbook/src/grammar_impl.hpp (contents, props changed)
trunk/tools/quickbook/src/rule_store.hpp (contents, props changed)
Removed:
trunk/tools/quickbook/src/phrase_grammar.hpp
Text files modified:
trunk/tools/quickbook/src/Jamfile.v2 | 1
trunk/tools/quickbook/src/actions.cpp | 8
trunk/tools/quickbook/src/block_grammar.cpp | 422 ++++++++++++++++-----------------
trunk/tools/quickbook/src/doc_info_grammar.cpp | 208 +++++++---------
trunk/tools/quickbook/src/grammar.hpp | 85 ++----
trunk/tools/quickbook/src/phrase_grammar.cpp | 495 ++++++++++++++++++---------------------
trunk/tools/quickbook/src/quickbook.cpp | 11
trunk/tools/quickbook/src/scoped_block.hpp | 3
trunk/tools/quickbook/src/syntax_highlight.hpp | 26 -
9 files changed, 579 insertions(+), 680 deletions(-)
Modified: trunk/tools/quickbook/src/Jamfile.v2
==============================================================================
--- trunk/tools/quickbook/src/Jamfile.v2 (original)
+++ trunk/tools/quickbook/src/Jamfile.v2 2010-12-19 08:29:25 EST (Sun, 19 Dec 2010)
@@ -30,6 +30,7 @@
code_snippet.cpp
markups.cpp
syntax_highlight.cpp
+ grammar.cpp
block_grammar.cpp
phrase_grammar.cpp
doc_info_grammar.cpp
Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp (original)
+++ trunk/tools/quickbook/src/actions.cpp 2010-12-19 08:29:25 EST (Sun, 19 Dec 2010)
@@ -810,17 +810,17 @@
}
else if (!body.is_block)
{
- simple_phrase_grammar phrase_p(actions);
+ quickbook_grammar g(actions);
// do a phrase level parse
iterator first(body.content.begin(), body.content.end(),
position(body.position.file.c_str(), body.position.line, body.position.column));
iterator last(body.content.end(), body.content.end());
- return call_parse(first, last, phrase_p).full;
+ return cl::parse(first, last, g.simple_phrase).full;
}
else
{
- block_grammar block_p(actions, true);
+ quickbook_grammar g(actions, true);
// do a block level parse
// ensure that we have enough trailing newlines to eliminate
@@ -830,7 +830,7 @@
iterator first(content.begin(), content.end(),
position(body.position.file.c_str(), body.position.line, body.position.column));
iterator last(content.end(), content.end());
- return call_parse(first, last, block_p).full;
+ return cl::parse(first, last, g.block).full;
}
}
}
Modified: trunk/tools/quickbook/src/block_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/block_grammar.cpp (original)
+++ trunk/tools/quickbook/src/block_grammar.cpp 2010-12-19 08:29:25 EST (Sun, 19 Dec 2010)
@@ -8,10 +8,10 @@
http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
-#include "phrase_grammar.hpp"
+#include "scoped_block.hpp"
#include "utils.hpp"
#include "actions_class.hpp"
-#include "scoped_block.hpp"
+#include "grammar_impl.hpp"
#include <boost/spirit/include/classic_confix.hpp>
#include <boost/spirit/include/classic_chset.hpp>
#include <boost/spirit/include/classic_assign_actor.hpp>
@@ -23,15 +23,10 @@
{
namespace cl = boost::spirit::classic;
- template <typename Scanner>
- struct block_grammar::definition
+ struct block_grammar_local
{
- definition(block_grammar const&);
-
- bool no_eols;
-
- cl::rule<Scanner>
- start_, blocks, block_markup, block_markup_start,
+ cl::rule<scanner>
+ blocks, block_markup, block_markup_start,
code, code_line, blank_line,
paragraph, space, blank, comment, h, h1, h2,
h3, h4, h5, h6, hr, blurb, blockquote,
@@ -47,108 +42,100 @@
element_id, element_id_1_5, element_id_1_6;
cl::symbols<> paragraph_end_markups;
-
- cl::symbols<cl::rule<Scanner>*> block_keyword_rules, block_symbol_rules;
- cl::rule<Scanner> block_keyword_rule;
-
- phrase_grammar common;
-
- cl::rule<Scanner> const&
- start() const { return start_; }
+ cl::rule<scanner> block_keyword_rule;
};
- template <typename Scanner>
- block_grammar::definition<Scanner>::definition(block_grammar const& self)
- : no_eols(true)
- , common(self.actions, no_eols)
+ void quickbook_grammar::impl::init_block(bool skip_initial_spaces)
{
using detail::var;
- quickbook::actions& actions = self.actions;
- if (self.skip_initial_spaces)
+ block_grammar_local& local = store_.create();
+
+ if (skip_initial_spaces)
{
- start_ =
- *(cl::blank_p | comment) >> blocks >> blank
+ block_start =
+ *(cl::blank_p | local.comment) >> local.blocks >> local.blank
;
}
else
{
- start_ =
- blocks >> blank
+ block_start =
+ local.blocks >> local.blank
;
}
- blocks =
- *( block_markup
- | code
- | list [actions.list]
- | hr [actions.hr]
- | +eol
- | paragraph [actions.inside_paragraph]
+ local.blocks =
+ *( local.block_markup
+ | local.code
+ | local.list [actions.list]
+ | local.hr [actions.hr]
+ | +local.eol
+ | local.paragraph [actions.inside_paragraph]
)
;
- space =
- *(cl::space_p | comment)
+ local.space =
+ *(cl::space_p | local.comment)
;
- blank =
- *(cl::blank_p | comment)
+ local.blank =
+ *(cl::blank_p | local.comment)
;
- eol = blank >> cl::eol_p
+ local.eol = local.blank >> cl::eol_p
;
- phrase_end =
+ local.phrase_end =
']' |
cl::if_p(var(no_eols))
[
- eol >> *cl::blank_p >> cl::eol_p
+ local.eol >> *cl::blank_p >> cl::eol_p
// Make sure that we don't go
] // past a single block, except
; // when preformatted.
// Follows after an alphanumeric identifier - ensures that it doesn't
// match an empty space in the middle of the identifier.
- hard_space =
- (cl::eps_p - (cl::alnum_p | '_')) >> space // must not be preceded by
- ; // alpha-numeric or underscore
+ local.hard_space =
+ (cl::eps_p - (cl::alnum_p | '_')) >> local.space
+ ;
- comment =
- "[/" >> *(dummy_block | (cl::anychar_p - ']')) >> ']'
+ local.comment =
+ "[/" >> *(local.dummy_block | (cl::anychar_p - ']')) >> ']'
;
- dummy_block =
- '[' >> *(dummy_block | (cl::anychar_p - ']')) >> ']'
+ local.dummy_block =
+ '[' >> *(local.dummy_block | (cl::anychar_p - ']')) >> ']'
;
- hr =
+ local.hr =
cl::str_p("----")
- >> *(cl::anychar_p - eol)
- >> +eol
+ >> *(cl::anychar_p - local.eol)
+ >> +local.eol
;
- block_markup
- = block_markup_start
- >> block_keyword_rule
- >> ( (space >> ']' >> +eol)
+ local.block_markup
+ = local.block_markup_start
+ >> local.block_keyword_rule
+ >> ( (local.space >> ']' >> +local.eol)
| cl::eps_p [actions.error]
)
;
- block_markup_start
- = '[' >> space
- >> ( block_keyword_rules [detail::assign_rule(block_keyword_rule)]
+ local.block_markup_start
+ = '[' >> local.space
+ >> ( block_keyword_rules [detail::assign_rule(local.block_keyword_rule)]
>> (cl::eps_p - (cl::alnum_p | '_'))
- | block_symbol_rules [detail::assign_rule(block_keyword_rule)]
+ | block_symbol_rules [detail::assign_rule(local.block_keyword_rule)]
)
;
- element_id =
+ local.element_id =
':'
>>
(
- cl::if_p(qbk_since(105u)) [space]
+ cl::if_p(qbk_since(105u))
+ [local.space]
>> (+(cl::alnum_p | '_')) [cl::assign_a(actions.element_id)]
| cl::eps_p [actions.element_id_warning]
[cl::assign_a(actions.element_id)]
@@ -156,18 +143,18 @@
| cl::eps_p [cl::assign_a(actions.element_id)]
;
- element_id_1_5 =
+ local.element_id_1_5 =
cl::if_p(qbk_since(105u)) [
- element_id
+ local.element_id
]
.else_p [
cl::eps_p [cl::assign_a(actions.element_id)]
]
;
- element_id_1_6 =
+ local.element_id_1_6 =
cl::if_p(qbk_since(106u)) [
- element_id
+ local.element_id
]
.else_p [
cl::eps_p [cl::assign_a(actions.element_id)]
@@ -175,326 +162,327 @@
;
block_keyword_rules.add
- ("section", &begin_section)
- ("endsect", &end_section)
+ ("section", &local.begin_section)
+ ("endsect", &local.end_section)
;
- begin_section =
- space
- >> element_id
- >> space
- >> inner_phrase [actions.begin_section]
+ local.begin_section =
+ local.space
+ >> local.element_id
+ >> local.space
+ >> local.inner_phrase [actions.begin_section]
;
- end_section =
+ local.end_section =
cl::eps_p [actions.end_section]
;
block_keyword_rules.add
- ("heading", &h)
- ("h1", &h1)
- ("h2", &h2)
- ("h3", &h3)
- ("h4", &h4)
- ("h5", &h5)
- ("h6", &h6)
- ;
-
- h = space >> element_id_1_6 >> space >> inner_phrase [actions.h];
- h1 = space >> element_id_1_6 >> space >> inner_phrase [actions.h1];
- h2 = space >> element_id_1_6 >> space >> inner_phrase [actions.h2];
- h3 = space >> element_id_1_6 >> space >> inner_phrase [actions.h3];
- h4 = space >> element_id_1_6 >> space >> inner_phrase [actions.h4];
- h5 = space >> element_id_1_6 >> space >> inner_phrase [actions.h5];
- h6 = space >> element_id_1_6 >> space >> inner_phrase [actions.h6];
+ ("heading", &local.h)
+ ("h1", &local.h1)
+ ("h2", &local.h2)
+ ("h3", &local.h3)
+ ("h4", &local.h4)
+ ("h5", &local.h5)
+ ("h6", &local.h6)
+ ;
+
+ local.h = local.space >> local.element_id_1_6 >> local.space >> local.inner_phrase [actions.h];
+ local.h1 = local.space >> local.element_id_1_6 >> local.space >> local.inner_phrase [actions.h1];
+ local.h2 = local.space >> local.element_id_1_6 >> local.space >> local.inner_phrase [actions.h2];
+ local.h3 = local.space >> local.element_id_1_6 >> local.space >> local.inner_phrase [actions.h3];
+ local.h4 = local.space >> local.element_id_1_6 >> local.space >> local.inner_phrase [actions.h4];
+ local.h5 = local.space >> local.element_id_1_6 >> local.space >> local.inner_phrase [actions.h5];
+ local.h6 = local.space >> local.element_id_1_6 >> local.space >> local.inner_phrase [actions.h6];
static const bool true_ = true;
static const bool false_ = false;
- inside_paragraph =
- phrase [actions.inside_paragraph]
+ local.inside_paragraph =
+ local.phrase [actions.inside_paragraph]
>> *(
- +eol >> phrase [actions.inside_paragraph]
+ +local.eol >> local.phrase [actions.inside_paragraph]
)
;
- block_keyword_rules.add("blurb", &blurb);
+ block_keyword_rules.add("blurb", &local.blurb);
- blurb =
- scoped_block(actions)[inside_paragraph]
+ local.blurb =
+ scoped_block(actions)[local.inside_paragraph]
[actions.blurb]
;
block_symbol_rules.add
- (":", &blockquote)
+ (":", &local.blockquote)
;
- blockquote =
- blank >> scoped_block(actions)[inside_paragraph]
+ local.blockquote =
+ local.blank >> scoped_block(actions)[local.inside_paragraph]
[actions.blockquote]
;
block_keyword_rules.add
- ("warning", &warning)
- ("caution", &caution)
- ("important", &important)
- ("note", ¬e)
- ("tip", &tip)
+ ("warning", &local.warning)
+ ("caution", &local.caution)
+ ("important", &local.important)
+ ("note", &local.note)
+ ("tip", &local.tip)
;
- warning =
- scoped_block(actions)[inside_paragraph]
+ local.warning =
+ scoped_block(actions)[local.inside_paragraph]
[actions.warning]
;
- caution =
- scoped_block(actions)[inside_paragraph]
+ local.caution =
+ scoped_block(actions)[local.inside_paragraph]
[actions.caution]
;
- important =
- scoped_block(actions)[inside_paragraph]
+ local.important =
+ scoped_block(actions)[local.inside_paragraph]
[actions.important]
;
- note =
- scoped_block(actions)[inside_paragraph]
+ local.note =
+ scoped_block(actions)[local.inside_paragraph]
[actions.note]
;
- tip =
- scoped_block(actions)[inside_paragraph]
+ local.tip =
+ scoped_block(actions)[local.inside_paragraph]
[actions.tip]
;
block_keyword_rules.add
- ("pre", &preformatted)
+ ("pre", &local.preformatted)
;
- preformatted =
- space [cl::assign_a(no_eols, false_)]
- >> !eol >> phrase [actions.preformatted]
+ local.preformatted =
+ local.space [cl::assign_a(no_eols, false_)]
+ >> !local.eol >> local.phrase [actions.preformatted]
>> cl::eps_p [cl::assign_a(no_eols, true_)]
;
- macro_identifier =
+ local.macro_identifier =
+(cl::anychar_p - (cl::space_p | ']'))
;
block_keyword_rules.add
- ("def", &def_macro)
+ ("def", &local.def_macro)
;
- def_macro =
- space
- >> macro_identifier [actions.macro_identifier]
- >> blank >> phrase [actions.macro_definition]
+ local.def_macro =
+ local.space
+ >> local.macro_identifier [actions.macro_identifier]
+ >> local.blank >> local.phrase [actions.macro_definition]
;
- identifier =
+ local.identifier =
(cl::alpha_p | '_') >> *(cl::alnum_p | '_')
;
- template_id =
- identifier | (cl::punct_p - (cl::ch_p('[') | ']'))
+ local.template_id =
+ local.identifier | (cl::punct_p - (cl::ch_p('[') | ']'))
;
block_keyword_rules.add
- ("template", &template_)
+ ("template", &local.template_)
;
- template_ =
- space
- >> template_id [cl::assign_a(actions.template_identifier)]
+ local.template_ =
+ local.space
+ >> local.template_id [cl::assign_a(actions.template_identifier)]
[cl::clear_a(actions.template_info)]
>>
!(
- space >> '['
+ local.space >> '['
>> *(
- space >> template_id [cl::push_back_a(actions.template_info)]
+ local.space
+ >> local.template_id [cl::push_back_a(actions.template_info)]
)
- >> space >> ']'
+ >> local.space >> ']'
)
>> ( cl::eps_p(*cl::blank_p >> cl::eol_p)
[cl::assign_a(actions.template_block, true_)]
| cl::eps_p [cl::assign_a(actions.template_block, false_)]
)
- >> template_body [actions.template_body]
+ >> local.template_body [actions.template_body]
;
- template_body =
- *(('[' >> template_body >> ']') | (cl::anychar_p - ']'))
- >> cl::eps_p(space >> ']')
- >> space
+ local.template_body =
+ *(('[' >> local.template_body >> ']') | (cl::anychar_p - ']'))
+ >> cl::eps_p(local.space >> ']')
+ >> local.space
;
block_keyword_rules.add
- ("variablelist", &variablelist)
+ ("variablelist", &local.variablelist)
;
- variablelist =
- (cl::eps_p(*cl::blank_p >> cl::eol_p) | space)
- >> (*(cl::anychar_p - eol)) [cl::assign_a(actions.table_title)]
- >> (+eol) [actions.output_pre]
- >> *varlistentry
+ local.variablelist =
+ (cl::eps_p(*cl::blank_p >> cl::eol_p) | local.space)
+ >> (*(cl::anychar_p - local.eol)) [cl::assign_a(actions.table_title)]
+ >> (+local.eol) [actions.output_pre]
+ >> *local.varlistentry
>> cl::eps_p [actions.variablelist]
;
- varlistentry =
- space
+ local.varlistentry =
+ local.space
>> cl::ch_p('[') [actions.start_varlistentry]
>>
(
(
- varlistterm
- >> ( scoped_block(actions) [+varlistitem]
+ local.varlistterm
+ >> ( scoped_block(actions) [+local.varlistitem]
[actions.varlistitem]
| cl::eps_p [actions.error]
)
>> cl::ch_p(']') [actions.end_varlistentry]
- >> space
+ >> local.space
)
| cl::eps_p [actions.error]
)
;
- varlistterm =
- space
+ local.varlistterm =
+ local.space
>> cl::ch_p('[') [actions.start_varlistterm]
>>
(
(
- phrase
+ local.phrase
>> cl::ch_p(']') [actions.end_varlistterm]
- >> space
+ >> local.space
)
| cl::eps_p [actions.error]
)
;
- varlistitem =
- space
+ local.varlistitem =
+ local.space
>> cl::ch_p('[')
>>
(
(
- inside_paragraph
+ local.inside_paragraph
>> cl::ch_p(']')
- >> space
+ >> local.space
)
| cl::eps_p [actions.error]
)
;
block_keyword_rules.add
- ("table", &table)
+ ("table", &local.table)
;
- table =
- (cl::eps_p(*cl::blank_p >> cl::eol_p) | space)
- >> element_id_1_5
- >> (cl::eps_p(*cl::blank_p >> cl::eol_p) | space)
- >> (*(cl::anychar_p - eol)) [cl::assign_a(actions.table_title)]
- >> (+eol) [actions.output_pre]
- >> *table_row
+ local.table =
+ (cl::eps_p(*cl::blank_p >> cl::eol_p) | local.space)
+ >> local.element_id_1_5
+ >> (cl::eps_p(*cl::blank_p >> cl::eol_p) | local.space)
+ >> (*(cl::anychar_p - local.eol)) [cl::assign_a(actions.table_title)]
+ >> (+local.eol) [actions.output_pre]
+ >> *local.table_row
>> cl::eps_p [actions.table]
;
- table_row =
- space
+ local.table_row =
+ local.space
>> cl::ch_p('[') [actions.start_row]
>>
(
(
- *table_cell
+ *local.table_cell
>> cl::ch_p(']') [actions.end_row]
- >> space
+ >> local.space
)
| cl::eps_p [actions.error]
)
;
- table_cell =
- space
+ local.table_cell =
+ local.space
>> cl::ch_p('[')
>> ( scoped_block(actions) [
- inside_paragraph
+ local.inside_paragraph
>> cl::ch_p(']')
- >> space
+ >> local.space
] [actions.cell]
| cl::eps_p [actions.error]
)
;
block_keyword_rules.add
- ("xinclude", &xinclude)
- ("import", &import)
- ("include", &include)
+ ("xinclude", &local.xinclude)
+ ("import", &local.import)
+ ("include", &local.include)
;
- xinclude =
- space
- >> (*(cl::anychar_p -
- phrase_end)) [actions.xinclude]
+ local.xinclude =
+ local.space
+ >> (*(cl::anychar_p - local.phrase_end))
+ [actions.xinclude]
;
- import =
- space
- >> (*(cl::anychar_p -
- phrase_end)) [actions.import]
+ local.import =
+ local.space
+ >> (*(cl::anychar_p - local.phrase_end))
+ [actions.import]
;
- include =
- space
+ local.include =
+ local.space
>>
!(
':'
>> (*((cl::alnum_p | '_') - cl::space_p))
[cl::assign_a(actions.include_doc_id)]
- >> space
+ >> local.space
)
- >> (*(cl::anychar_p -
- phrase_end)) [actions.include]
+ >> (*(cl::anychar_p - local.phrase_end))
+ [actions.include]
;
- code =
+ local.code =
(
- code_line
- >> *(*blank_line >> code_line)
+ local.code_line
+ >> *(*local.blank_line >> local.code_line)
) [actions.code]
- >> *eol
+ >> *local.eol
;
- code_line =
+ local.code_line =
cl::blank_p >> *(cl::anychar_p - cl::eol_p) >> cl::eol_p
;
- blank_line =
+ local.blank_line =
*cl::blank_p >> cl::eol_p
;
- list =
+ local.list =
cl::eps_p(cl::ch_p('*') | '#') >>
+(
(*cl::blank_p
>> (cl::ch_p('*') | '#')) [actions.list_format]
>> *cl::blank_p
- >> list_item
+ >> local.list_item
) [actions.list_item]
;
- list_item =
+ local.list_item =
*( common
| (cl::anychar_p -
( cl::eol_p >> *cl::blank_p >> cl::eps_p(cl::ch_p('*') | '#')
- | (eol >> eol)
+ | (local.eol >> local.eol)
)
) [actions.plain_char]
)
- >> +eol
+ >> +local.eol
;
- paragraph_end_markups =
+ local.paragraph_end_markups =
"section", "endsect", "heading",
"h1", "h2", "h3", "h4", "h5", "h6",
"blurb", "pre", "def", "table", "include", "xinclude",
@@ -502,38 +490,34 @@
"important", "note", "tip", ":"
;
- paragraph_end =
- '[' >> space >> paragraph_end_markups >> hard_space | eol >> *cl::blank_p >> cl::eol_p
+ local.paragraph_end =
+ '[' >> local.space >> local.paragraph_end_markups >> local.hard_space
+ | local.eol >> *cl::blank_p >> cl::eol_p
;
- paragraph =
+ local.paragraph =
+( common
- | (cl::eps_p - paragraph_end)
+ | (cl::eps_p - // Make sure we don't go past
+ local.paragraph_end) // a single block.
>> ( cl::space_p [actions.space_char]
| cl::anychar_p [actions.plain_char]
)
)
- >> (cl::eps_p('[') | +eol)
+ >> (cl::eps_p('[') | +local.eol)
;
- inner_phrase =
+ local.inner_phrase =
cl::eps_p [actions.inner_phrase_pre]
- >> phrase
+ >> local.phrase
>> cl::eps_p [actions.inner_phrase_post]
;
- phrase =
+ local.phrase =
*( common
- | comment
- | (cl::anychar_p -
- phrase_end) [actions.plain_char]
+ | local.comment
+ | (cl::anychar_p - local.phrase_end)
+ [actions.plain_char]
)
;
}
-
- cl::parse_info<iterator> call_parse(
- iterator& first, iterator last, block_grammar& g)
- {
- return boost::spirit::classic::parse(first, last, g);
- }
}
Modified: trunk/tools/quickbook/src/doc_info_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/doc_info_grammar.cpp (original)
+++ trunk/tools/quickbook/src/doc_info_grammar.cpp 2010-12-19 08:29:25 EST (Sun, 19 Dec 2010)
@@ -8,7 +8,7 @@
http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
-#include "phrase_grammar.hpp"
+#include "grammar_impl.hpp"
#include "actions_class.hpp"
#include <boost/spirit/include/classic_core.hpp>
#include <boost/spirit/include/classic_actor.hpp>
@@ -20,159 +20,150 @@
{
namespace cl = boost::spirit::classic;
- template <typename Scanner>
- struct doc_info_grammar::definition
+ struct doc_info_grammar_local
{
- definition(doc_info_grammar const&);
-
- typedef cl::uint_parser<int, 10, 1, 2> uint2_t;
-
- bool unused;
- std::string category;
- cl::rule<Scanner>
- doc_info, doc_title, doc_version, doc_id, doc_dirname,
+ cl::rule<scanner>
+ doc_title, doc_version, doc_id, doc_dirname,
doc_copyright, doc_purpose, doc_category, doc_authors,
doc_author, space, hard_space, doc_license,
doc_last_revision, doc_source_mode, doc_biblioid, doc_lang,
phrase, quickbook_version, char_, comment, dummy_block;
- phrase_grammar common;
cl::symbols<> doc_types;
-
- cl::rule<Scanner> const&
- start() const { return doc_info; }
};
- template <typename Scanner>
- doc_info_grammar::definition<Scanner>::definition(doc_info_grammar const& self)
- : unused(false), common(self.actions, unused)
+ void quickbook_grammar::impl::init_doc_info()
{
- quickbook::actions& actions = self.actions;
+ doc_info_grammar_local& local = store_.create();
- doc_types =
+ typedef cl::uint_parser<int, 10, 1, 2> uint2_t;
+
+ local.doc_types =
"book", "article", "library", "chapter", "part"
, "appendix", "preface", "qandadiv", "qandaset"
, "reference", "set"
;
- doc_info =
- space
- >> '[' >> space
- >> (doc_types >> cl::eps_p) [cl::assign_a(actions.doc_type)]
- >> hard_space
- >> ( *(~cl::eps_p(cl::ch_p('[') | ']' | cl::eol_p) >> char_)
+ doc_info_details =
+ local.space
+ >> '[' >> local.space
+ >> (local.doc_types >> cl::eps_p)
+ [cl::assign_a(actions.doc_type)]
+ >> local.hard_space
+ >> ( *(~cl::eps_p(cl::ch_p('[') | ']' | cl::eol_p) >> local.char_)
) [actions.extract_doc_title]
>> !(
- space >> '[' >>
- quickbook_version
- >> space >> ']'
+ local.space >> '[' >>
+ local.quickbook_version
+ >> local.space >> ']'
)
>>
*(
- space >> '[' >>
+ local.space >> '[' >>
(
- doc_version
- | doc_id
- | doc_dirname
- | doc_copyright [cl::push_back_a(actions.doc_copyrights, actions.copyright)]
- | doc_purpose
- | doc_category
- | doc_authors
- | doc_license
- | doc_last_revision
- | doc_source_mode
- | doc_biblioid
- | doc_lang
+ local.doc_version
+ | local.doc_id
+ | local.doc_dirname
+ | local.doc_copyright [cl::push_back_a(actions.doc_copyrights, actions.copyright)]
+ | local.doc_purpose
+ | local.doc_category
+ | local.doc_authors
+ | local.doc_license
+ | local.doc_last_revision
+ | local.doc_source_mode
+ | local.doc_biblioid
+ | local.doc_lang
)
- >> space >> ']' >> +cl::eol_p
+ >> local.space >> ']' >> +cl::eol_p
)
- >> space >> ']' >> +cl::eol_p
+ >> local.space >> ']' >> +cl::eol_p
;
- quickbook_version =
- "quickbook" >> hard_space
+ local.quickbook_version =
+ "quickbook" >> local.hard_space
>> ( cl::uint_p [cl::assign_a(qbk_major_version)]
>> '.'
>> uint2_t() [cl::assign_a(qbk_minor_version)]
)
;
- doc_version =
- "version" >> hard_space
- >> (*(~cl::eps_p(']') >> char_))
+ local.doc_version =
+ "version" >> local.hard_space
+ >> (*(~cl::eps_p(']') >> local.char_))
[actions.extract_doc_version]
;
// TODO: Restrictions on doc_id?
- doc_id =
- "id" >> hard_space
- >> (*(~cl::eps_p(']') >> char_))
+ local.doc_id =
+ "id" >> local.hard_space
+ >> (*(~cl::eps_p(']') >> local.char_))
[actions.extract_doc_id]
;
// TODO: Restrictions on doc_dirname?
- doc_dirname =
- "dirname" >> hard_space
- >> (*(~cl::eps_p(']') >> char_))
+ local.doc_dirname =
+ "dirname" >> local.hard_space
+ >> (*(~cl::eps_p(']') >> local.char_))
[actions.extract_doc_dirname]
;
- doc_copyright =
- "copyright" >> hard_space [cl::clear_a(actions.copyright.first)]
+ local.doc_copyright =
+ "copyright"
+ >> local.hard_space [cl::clear_a(actions.copyright.first)]
>> +( cl::repeat_p(4)[cl::digit_p]
[cl::push_back_a(actions.copyright.first)]
- >> space
+ >> local.space
)
- >> space
- >> (*(~cl::eps_p(']') >> char_))
+ >> local.space
+ >> (*(~cl::eps_p(']') >> local.char_))
[actions.extract_copyright_second]
;
- doc_purpose =
- "purpose" >> hard_space
- >> phrase [actions.extract_doc_purpose]
+ local.doc_purpose =
+ "purpose" >> local.hard_space
+ >> local.phrase [actions.extract_doc_purpose]
;
- doc_category =
- "category" >> hard_space
- >> (*(~cl::eps_p(']') >> char_))
+ local.doc_category =
+ "category" >> local.hard_space
+ >> (*(~cl::eps_p(']') >> local.char_))
[actions.extract_doc_category]
[cl::push_back_a(actions.doc_categories, actions.doc_category)]
;
- doc_author =
- '[' >> space
- >> (*(~cl::eps_p(',') >> char_))
+ local.doc_author =
+ '[' >> local.space
+ >> (*(~cl::eps_p(',') >> local.char_))
[actions.extract_name_second]
- >> ',' >> space
- >> (*(~cl::eps_p(']') >> char_))
+ >> ',' >> local.space
+ >> (*(~cl::eps_p(']') >> local.char_))
[actions.extract_name_first]
>> ']'
;
- doc_authors =
+ local.doc_authors =
"authors"
- >> hard_space
- >> doc_author [cl::push_back_a(actions.doc_authors, actions.name)]
- >> space
- >> *( !(cl::ch_p(',') >> space)
- >> doc_author [cl::push_back_a(actions.doc_authors, actions.name)]
- >> space
+ >> local.hard_space
+ >> local.doc_author [cl::push_back_a(actions.doc_authors, actions.name)]
+ >> local.space
+ >> *( !(cl::ch_p(',') >> local.space)
+ >> local.doc_author [cl::push_back_a(actions.doc_authors, actions.name)]
+ >> local.space
)
;
- doc_license =
- "license" >> hard_space
- >> phrase [actions.extract_doc_license]
+ local.doc_license =
+ "license" >> local.hard_space
+ >> local.phrase [actions.extract_doc_license]
;
- doc_last_revision =
- "last-revision" >> hard_space
- >> (*(~cl::eps_p(']') >> char_))
+ local.doc_last_revision =
+ "last-revision" >> local.hard_space
+ >> (*(~cl::eps_p(']') >> local.char_))
[actions.extract_doc_last_revision]
;
- doc_source_mode =
- "source-mode" >> hard_space
+ local.doc_source_mode =
+ "source-mode" >> local.hard_space
>> (
cl::str_p("c++")
| "python"
@@ -180,46 +171,45 @@
) [cl::assign_a(actions.source_mode)]
;
- doc_biblioid =
+ local.doc_biblioid =
"biblioid"
- >> hard_space
+ >> local.hard_space
>> (+cl::alnum_p) [cl::assign_a(actions.doc_biblioid.first)]
- >> hard_space
- >> (+(~cl::eps_p(']') >> char_))
+ >> local.hard_space
+ >> (+(~cl::eps_p(']') >> local.char_))
[actions.extract_doc_biblioid]
[cl::push_back_a(actions.doc_biblioid_items, actions.doc_biblioid)]
;
- doc_lang =
- "lang" >> hard_space
- >> (*(~cl::eps_p(']') >> char_))
+ local.doc_lang =
+ "lang" >> local.hard_space
+ >> (*(~cl::eps_p(']') >> local.char_))
[actions.extract_doc_lang]
;
- comment =
- "[/" >> *(dummy_block | (cl::anychar_p - ']')) >> ']'
+ local.space =
+ *(cl::space_p | local.comment)
;
- dummy_block =
- '[' >> *(dummy_block | (cl::anychar_p - ']')) >> ']'
- ;
+ local.hard_space =
+ (cl::eps_p - (cl::alnum_p | '_')) >> local.space // must not be preceded by
+ ; // alpha-numeric or underscore
- space =
- *(cl::space_p | comment)
+ local.comment =
+ "[/" >> *(local.dummy_block | (cl::anychar_p - ']')) >> ']'
;
- hard_space =
- (cl::eps_p - (cl::alnum_p | '_')) >> space // must not be preceded by
- ; // alpha-numeric or underscore
+ local.dummy_block =
+ '[' >> *(local.dummy_block | (cl::anychar_p - ']')) >> ']'
+ ;
- phrase =
+ local.phrase =
*( common
- | comment
| (cl::anychar_p - ']') [actions.plain_char]
)
;
- char_ =
+ local.char_ =
cl::str_p("\\n") [actions.break_]
| "\\ " // ignore an escaped space
| '\\' >> cl::punct_p [actions.raw_char]
@@ -237,10 +227,4 @@
| cl::anychar_p [actions.plain_char]
;
}
-
- cl::parse_info<iterator> call_parse(
- iterator& first, iterator last, doc_info_grammar& g)
- {
- return boost::spirit::classic::parse(first, last, g);
- }
}
Added: trunk/tools/quickbook/src/grammar.cpp
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/src/grammar.cpp 2010-12-19 08:29:25 EST (Sun, 19 Dec 2010)
@@ -0,0 +1,39 @@
+/*=============================================================================
+ Copyright (c) 2002 2004 2006 Joel de Guzman
+ Copyright (c) 2004 Eric Niebler
+ Copyright (c) 2010 Daniel James
+ http://spirit.sourceforge.net/
+
+ Use, modification and distribution is subject to the Boost Software
+ License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+
+#include "grammar_impl.hpp"
+
+namespace quickbook
+{
+ quickbook_grammar::quickbook_grammar(quickbook::actions& a, bool skip_initial_spaces)
+ : impl_(new impl(a, skip_initial_spaces))
+ , command_line_macro(impl_->command_line, "command_line_macro")
+ , common(impl_->common, "phrase")
+ , simple_phrase(impl_->simple_phrase, "simple_phrase")
+ , block(impl_->block_start, "block")
+ , doc_info(impl_->doc_info_details, "doc_info")
+ {
+ }
+
+ quickbook_grammar::~quickbook_grammar()
+ {
+ }
+
+ quickbook_grammar::impl::impl(quickbook::actions& a, bool skip_initial_spaces)
+ : actions(a)
+ , no_eols(true)
+ , store_()
+ {
+ init_block(skip_initial_spaces);
+ init_phrase();
+ init_doc_info();
+ }
+}
Modified: trunk/tools/quickbook/src/grammar.hpp
==============================================================================
--- trunk/tools/quickbook/src/grammar.hpp (original)
+++ trunk/tools/quickbook/src/grammar.hpp 2010-12-19 08:29:25 EST (Sun, 19 Dec 2010)
@@ -24,77 +24,44 @@
typedef cl::scanner<iterator, cl::scanner_policies <
cl::iteration_policy, cl::match_policy, cl::action_policy> > scanner;
- struct doc_info_grammar
- : public cl::grammar<doc_info_grammar>
+ struct grammar
+ : public cl::grammar<grammar>
{
- doc_info_grammar(quickbook::actions& actions)
- : actions(actions) {}
+ grammar(cl::rule<scanner> const& start_rule, char const* /* name */)
+ : start_rule(start_rule) {}
template <typename Scanner>
- struct definition;
+ struct definition {
+ // TODO: Statically assert that Scanner == scanner.
+
+ definition(grammar const& self) : start_rule(self.start_rule) {}
+
+ cl::rule<Scanner> const& start() const { return start_rule; }
- quickbook::actions& actions;
- };
-
- struct block_grammar : cl::grammar<block_grammar>
- {
- block_grammar(quickbook::actions& actions_, bool skip_initial_spaces = false)
- : actions(actions_), skip_initial_spaces(skip_initial_spaces) { }
-
- template <typename Scanner>
- struct definition;
-
- quickbook::actions& actions;
- bool const skip_initial_spaces;
- };
-
- struct phrase_grammar
- : cl::grammar<phrase_grammar>
- {
- phrase_grammar(quickbook::actions& actions, bool& no_eols)
- : no_eols(no_eols), actions(actions) {}
+ cl::rule<Scanner> const& start_rule;
+ };
- template <typename Scanner>
- struct definition;
-
- bool& no_eols;
- quickbook::actions& actions;
+ cl::rule<scanner> const& start_rule;
};
- struct simple_phrase_grammar
- : public cl::grammar<simple_phrase_grammar >
+ class quickbook_grammar
{
- simple_phrase_grammar(quickbook::actions& actions)
- : actions(actions) {}
+ public:
+ struct impl;
- template <typename Scanner>
- struct definition;
+ private:
+ boost::scoped_ptr<impl> impl_;
- quickbook::actions& actions;
- };
+ public:
+ grammar command_line_macro;
+ grammar common;
+ grammar simple_phrase;
+ grammar block;
+ grammar doc_info;
- struct command_line_grammar
- : public cl::grammar<command_line_grammar>
- {
- command_line_grammar(quickbook::actions& actions)
- : actions(actions) {}
-
- template <typename Scanner>
- struct definition;
-
- quickbook::actions& actions;
+ quickbook_grammar(quickbook::actions&, bool skip_initial_spaces = false);
+ ~quickbook_grammar();
};
-
- cl::parse_info<iterator> call_parse(
- iterator&, iterator, doc_info_grammar&);
- cl::parse_info<iterator> call_parse(
- iterator&, iterator, block_grammar&);
- cl::parse_info<iterator> call_parse(
- iterator&, iterator, phrase_grammar&);
- cl::parse_info<iterator> call_parse(
- iterator&, iterator, simple_phrase_grammar&);
- cl::parse_info<iterator> call_parse(
- iterator&, iterator, command_line_grammar&);
}
#endif
Added: trunk/tools/quickbook/src/grammar_impl.hpp
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/src/grammar_impl.hpp 2010-12-19 08:29:25 EST (Sun, 19 Dec 2010)
@@ -0,0 +1,54 @@
+/*=============================================================================
+ Copyright (c) 2002 2004 2006 Joel de Guzman
+ Copyright (c) 2004 Eric Niebler
+ Copyright (c) 2010 Daniel James
+ http://spirit.sourceforge.net/
+
+ Use, modification and distribution is subject to the Boost Software
+ License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_QUICKBOOK_GRAMMARS_IMPL_HPP)
+#define BOOST_SPIRIT_QUICKBOOK_GRAMMARS_IMPL_HPP
+
+#include "grammar.hpp"
+#include "rule_store.hpp"
+#include <boost/spirit/include/classic_symbols.hpp>
+
+namespace quickbook
+{
+ namespace cl = boost::spirit::classic;
+
+ struct quickbook_grammar::impl
+ {
+ quickbook::actions& actions;
+ bool no_eols;
+ rule_store store_;
+
+ // phrase
+ cl::rule<scanner> common;
+ cl::rule<scanner> simple_phrase;
+ cl::rule<scanner> phrase;
+ cl::rule<scanner> command_line;
+ cl::symbols<cl::rule<scanner>*> phrase_keyword_rules;
+ cl::symbols<cl::rule<scanner>*> phrase_symbol_rules;
+
+ // block
+ cl::rule<scanner> block_start;
+ cl::symbols<cl::rule<scanner>*> block_keyword_rules;
+ cl::symbols<cl::rule<scanner>*> block_symbol_rules;
+
+ // doc_info
+ cl::rule<scanner> doc_info_details;
+
+ impl(quickbook::actions&, bool);
+
+ private:
+
+ void init_block(bool);
+ void init_phrase();
+ void init_doc_info();
+ };
+}
+
+#endif // BOOST_SPIRIT_QUICKBOOK_GRAMMARS_HPP
Modified: trunk/tools/quickbook/src/phrase_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/phrase_grammar.cpp (original)
+++ trunk/tools/quickbook/src/phrase_grammar.cpp 2010-12-19 08:29:25 EST (Sun, 19 Dec 2010)
@@ -8,7 +8,7 @@
http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
-#include "phrase_grammar.hpp"
+#include "grammar_impl.hpp"
#include "actions_class.hpp"
#include "utils.hpp"
#include <boost/spirit/include/classic_core.hpp>
@@ -21,6 +21,8 @@
namespace quickbook
{
+ namespace cl = boost::spirit::classic;
+
template <typename Rule, typename Action>
inline void
simple_markup(
@@ -55,56 +57,79 @@
;
}
- template <typename Scanner>
- phrase_grammar::definition<Scanner>::definition(phrase_grammar const& self)
+ struct phrase_grammar_local
+ {
+ cl::rule<scanner>
+ space, blank, comment, phrase_markup, image,
+ simple_phrase_end, phrase_end, bold, italic, underline, teletype,
+ strikethrough, escape, url, 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, template_,
+ source_mode_cpp, source_mode_python, source_mode_teletype,
+ quote, code_block, footnote, replaceable, macro,
+ dummy_block, cond_phrase, macro_identifier, template_args,
+ template_args_1_4, template_arg_1_4,
+ template_inner_arg_1_4, brackets_1_4,
+ template_args_1_5, template_arg_1_5,
+ template_inner_arg_1_5, brackets_1_5,
+ command_line_macro_identifier, command_line_phrase
+ ;
+
+ cl::rule<scanner> phrase_keyword_rule;
+ };
+
+ void quickbook_grammar::impl::init_phrase()
{
using detail::var;
- quickbook::actions& actions = self.actions;
- space =
- *(cl::space_p | comment)
+ phrase_grammar_local& local = store_.create();
+
+ local.space =
+ *(cl::space_p | local.comment)
;
- blank =
- *(cl::blank_p | comment)
+ local.blank =
+ *(cl::blank_p | local.comment)
;
- eol = blank >> cl::eol_p
+ local.eol = local.blank >> cl::eol_p
;
- phrase_end =
+ local.phrase_end =
']' |
- cl::if_p(var(self.no_eols))
+ cl::if_p(var(no_eols))
[
- eol >> eol // Make sure that we don't go
+ local.eol >> local.eol // Make sure that we don't go
] // past a single block, except
; // when preformatted.
// Follows an alphanumeric identifier - ensures that it doesn't
// match an empty space in the middle of the identifier.
- hard_space =
- (cl::eps_p - (cl::alnum_p | '_')) >> space
+ local.hard_space =
+ (cl::eps_p - (cl::alnum_p | '_')) >> local.space
;
- comment =
- "[/" >> *(dummy_block | (cl::anychar_p - ']')) >> ']'
+ local.comment =
+ "[/" >> *(local.dummy_block | (cl::anychar_p - ']')) >> ']'
;
- dummy_block =
- '[' >> *(dummy_block | (cl::anychar_p - ']')) >> ']'
+ local.dummy_block =
+ '[' >> *(local.dummy_block | (cl::anychar_p - ']')) >> ']'
;
common =
- macro
- | phrase_markup
- | code_block
- | inline_code
- | simple_format
- | escape
- | comment
+ local.macro
+ | local.phrase_markup
+ | local.code_block
+ | local.inline_code
+ | local.simple_format
+ | local.escape
+ | local.comment
;
- macro =
+ local.macro =
// must not be followed by alpha or underscore
cl::eps_p(actions.macro
>> (cl::eps_p - (cl::alpha_p | '_')))
@@ -114,7 +139,7 @@
static const bool true_ = true;
static const bool false_ = false;
- template_ =
+ local.template_ =
(
cl::ch_p('`') [cl::assign_a(actions.template_escape,true_)]
|
@@ -126,76 +151,76 @@
>> actions.templates.scope
) [cl::assign_a(actions.template_identifier)]
[cl::clear_a(actions.template_args)]
- >> !template_args
+ >> !local.template_args
) | (
(actions.templates.scope
- >> cl::eps_p(hard_space)
+ >> cl::eps_p(local.hard_space)
) [cl::assign_a(actions.template_identifier)]
[cl::clear_a(actions.template_args)]
- >> space
- >> !template_args
+ >> local.space
+ >> !local.template_args
) )
>> cl::eps_p(']')
;
- template_args =
+ local.template_args =
cl::if_p(qbk_since(105u)) [
- template_args_1_5
+ local.template_args_1_5
].else_p [
- template_args_1_4
+ local.template_args_1_4
]
;
- template_args_1_4 = template_arg_1_4 >> *(".." >> template_arg_1_4);
+ local.template_args_1_4 = local.template_arg_1_4 >> *(".." >> local.template_arg_1_4);
- template_arg_1_4 =
+ local.template_arg_1_4 =
( cl::eps_p(*cl::blank_p >> cl::eol_p)
[cl::assign_a(actions.template_block, true_)]
| cl::eps_p [cl::assign_a(actions.template_block, false_)]
)
- >> template_inner_arg_1_4 [actions.template_arg]
+ >> local.template_inner_arg_1_4 [actions.template_arg]
;
- template_inner_arg_1_4 =
- +(brackets_1_4 | (cl::anychar_p - (cl::str_p("..") | ']')))
+ local.template_inner_arg_1_4 =
+ +(local.brackets_1_4 | (cl::anychar_p - (cl::str_p("..") | ']')))
;
- brackets_1_4 =
- '[' >> template_inner_arg_1_4 >> ']'
+ local.brackets_1_4 =
+ '[' >> local.template_inner_arg_1_4 >> ']'
;
- template_args_1_5 = template_arg_1_5 >> *(".." >> template_arg_1_5);
+ local.template_args_1_5 = local.template_arg_1_5 >> *(".." >> local.template_arg_1_5);
- template_arg_1_5 =
+ local.template_arg_1_5 =
( cl::eps_p(*cl::blank_p >> cl::eol_p)
[cl::assign_a(actions.template_block, true_)]
| cl::eps_p [cl::assign_a(actions.template_block, false_)]
)
- >> (+(brackets_1_5 | ('\\' >> cl::anychar_p) | (cl::anychar_p - (cl::str_p("..") | '[' | ']'))))
+ >> (+(local.brackets_1_5 | ('\\' >> cl::anychar_p) | (cl::anychar_p - (cl::str_p("..") | '[' | ']'))))
[actions.template_arg]
;
- template_inner_arg_1_5 =
- +(brackets_1_5 | ('\\' >> cl::anychar_p) | (cl::anychar_p - (cl::str_p('[') | ']')))
+ local.template_inner_arg_1_5 =
+ +(local.brackets_1_5 | ('\\' >> cl::anychar_p) | (cl::anychar_p - (cl::str_p('[') | ']')))
;
- brackets_1_5 =
- '[' >> template_inner_arg_1_5 >> ']'
+ local.brackets_1_5 =
+ '[' >> local.template_inner_arg_1_5 >> ']'
;
- inline_code =
+ local.inline_code =
'`' >>
(
*(cl::anychar_p -
( '`'
- | (eol >> eol) // Make sure that we don't go
+ | (local.eol >> local.eol)// Make sure that we don't go
) // past a single block
) >> cl::eps_p('`')
) [actions.inline_code]
>> '`'
;
- code_block =
+ local.code_block =
(
"```" >>
(
@@ -214,45 +239,45 @@
)
;
- simple_format =
- simple_bold
- | simple_italic
- | simple_underline
- | simple_teletype
- ;
-
- simple_phrase_end = '[' | phrase_end;
-
- simple_markup(simple_bold,
- '*', actions.simple_bold, simple_phrase_end);
- simple_markup(simple_italic,
- '/', actions.simple_italic, simple_phrase_end);
- simple_markup(simple_underline,
- '_', actions.simple_underline, simple_phrase_end);
- simple_markup(simple_teletype,
- '=', actions.simple_teletype, simple_phrase_end);
+ local.simple_format =
+ local.simple_bold
+ | local.simple_italic
+ | local.simple_underline
+ | local.simple_teletype
+ ;
+
+ local.simple_phrase_end = '[' | local.phrase_end;
+
+ simple_markup(local.simple_bold,
+ '*', actions.simple_bold, local.simple_phrase_end);
+ simple_markup(local.simple_italic,
+ '/', actions.simple_italic, local.simple_phrase_end);
+ simple_markup(local.simple_underline,
+ '_', actions.simple_underline, local.simple_phrase_end);
+ simple_markup(local.simple_teletype,
+ '=', actions.simple_teletype, local.simple_phrase_end);
phrase =
*( common
- | comment
- | (cl::anychar_p - phrase_end) [actions.plain_char]
+ | local.comment
+ | (cl::anychar_p - local.phrase_end) [actions.plain_char]
)
;
- phrase_markup
+ local.phrase_markup
= '['
- >> ( phrase_keyword_rules [detail::assign_rule(phrase_keyword_rule)]
+ >> ( phrase_keyword_rules [detail::assign_rule(local.phrase_keyword_rule)]
>> (cl::eps_p - (cl::alnum_p | '_'))
- >> phrase_keyword_rule
- | phrase_symbol_rules [detail::assign_rule(phrase_keyword_rule)]
- >> phrase_keyword_rule
- | template_ [actions.do_template]
+ >> local.phrase_keyword_rule
+ | phrase_symbol_rules [detail::assign_rule(local.phrase_keyword_rule)]
+ >> local.phrase_keyword_rule
+ | local.template_ [actions.do_template]
| cl::str_p("br") [actions.break_]
)
>> ']'
;
- escape =
+ local.escape =
cl::str_p("\\n") [actions.break_]
| cl::str_p("\\ ") // ignore an escaped space
| '\\' >> cl::punct_p [actions.raw_char]
@@ -261,317 +286,263 @@
| "\\U" >> cl::repeat_p(8) [cl::chset<>("0-9a-fA-F")]
[actions.escape_unicode]
| (
- ("'''" >> !eol) [actions.escape_pre]
+ ("'''" >> !local.eol) [actions.escape_pre]
>> *(cl::anychar_p - "'''") [actions.raw_char]
>> cl::str_p("'''") [actions.escape_post]
)
;
- macro_identifier =
+ local.macro_identifier =
+(cl::anychar_p - (cl::space_p | ']'))
;
phrase_symbol_rules.add
- ("?", &cond_phrase)
+ ("?", &local.cond_phrase)
;
- cond_phrase =
- blank
- >> macro_identifier [actions.cond_phrase_pre]
+ local.cond_phrase =
+ local.blank
+ >> local.macro_identifier [actions.cond_phrase_pre]
>> (!phrase) [actions.cond_phrase_post]
;
phrase_symbol_rules.add
- ("$", &image)
+ ("$", &local.image)
;
- image =
- blank [cl::clear_a(actions.attributes)]
+ local.image =
+ local.blank [cl::clear_a(actions.attributes)]
>> cl::if_p(qbk_since(105u)) [
(+(
*cl::space_p
- >> +(cl::anychar_p - (cl::space_p | phrase_end | '['))
+ >> +(cl::anychar_p - (cl::space_p | local.phrase_end | '['))
)) [cl::assign_a(actions.image_fileref)]
- >> hard_space
+ >> local.hard_space
>> *(
'['
>> (*(cl::alnum_p | '_')) [cl::assign_a(actions.attribute_name)]
- >> space
- >> (*(cl::anychar_p - (phrase_end | '[')))
+ >> local.space
+ >> (*(cl::anychar_p - (local.phrase_end | '[')))
[actions.attribute]
>> ']'
- >> space
+ >> local.space
)
].else_p [
- (*(cl::anychar_p - phrase_end))
+ (*(cl::anychar_p - local.phrase_end))
[cl::assign_a(actions.image_fileref)]
]
>> cl::eps_p(']') [actions.image]
;
phrase_symbol_rules.add
- ("@", &url)
+ ("@", &local.url)
;
- url =
+ local.url =
(*(cl::anychar_p -
- (']' | hard_space))) [actions.url_pre]
- >> hard_space
+ (']' | local.hard_space))) [actions.url_pre]
+ >> local.hard_space
>> phrase [actions.url_post]
;
phrase_keyword_rules.add
- ("link", &link)
+ ("link", &local.link)
;
- link =
- space
- >> (*(cl::anychar_p -
- (']' | hard_space))) [actions.link_pre]
- >> hard_space
+ local.link =
+ local.space
+ >> (*(cl::anychar_p - (']' | local.hard_space)))
+ [actions.link_pre]
+ >> local.hard_space
>> phrase [actions.link_post]
;
phrase_symbol_rules.add
- ("#", &anchor)
+ ("#", &local.anchor)
;
- anchor =
- blank
- >> (*(cl::anychar_p - phrase_end)) [actions.anchor]
+ local.anchor =
+ local.blank
+ >> (*(cl::anychar_p - local.phrase_end)) [actions.anchor]
;
phrase_keyword_rules.add
- ("funcref", &funcref)
- ("classref", &classref)
- ("memberref", &memberref)
- ("enumref", &enumref)
- ("macroref", ¯oref)
- ("headerref", &headerref)
- ("conceptref", &conceptref)
- ("globalref", &globalref)
+ ("funcref", &local.funcref)
+ ("classref", &local.classref)
+ ("memberref", &local.memberref)
+ ("enumref", &local.enumref)
+ ("macroref", &local.macroref)
+ ("headerref", &local.headerref)
+ ("conceptref", &local.conceptref)
+ ("globalref", &local.globalref)
;
- funcref =
- space
+ local.funcref =
+ local.space
>> (*(cl::anychar_p -
- (']' | hard_space))) [actions.funcref_pre]
- >> hard_space
+ (']' | local.hard_space))) [actions.funcref_pre]
+ >> local.hard_space
>> phrase [actions.funcref_post]
;
- classref =
- space
+ local.classref =
+ local.space
>> (*(cl::anychar_p -
- (']' | hard_space))) [actions.classref_pre]
- >> hard_space
+ (']' | local.hard_space))) [actions.classref_pre]
+ >> local.hard_space
>> phrase [actions.classref_post]
;
- memberref =
- space
+ local.memberref =
+ local.space
>> (*(cl::anychar_p -
- (']' | hard_space))) [actions.memberref_pre]
- >> hard_space
+ (']' | local.hard_space))) [actions.memberref_pre]
+ >> local.hard_space
>> phrase [actions.memberref_post]
;
- enumref =
- space
+ local.enumref =
+ local.space
>> (*(cl::anychar_p -
- (']' | hard_space))) [actions.enumref_pre]
- >> hard_space
+ (']' | local.hard_space))) [actions.enumref_pre]
+ >> local.hard_space
>> phrase [actions.enumref_post]
;
- macroref =
- space
+ local.macroref =
+ local.space
>> (*(cl::anychar_p -
- (']' | hard_space))) [actions.macroref_pre]
- >> hard_space
+ (']' | local.hard_space))) [actions.macroref_pre]
+ >> local.hard_space
>> phrase [actions.macroref_post]
;
- headerref =
- space
+ local.headerref =
+ local.space
>> (*(cl::anychar_p -
- (']' | hard_space))) [actions.headerref_pre]
- >> hard_space
+ (']' | local.hard_space))) [actions.headerref_pre]
+ >> local.hard_space
>> phrase [actions.headerref_post]
;
- conceptref =
- space
+ local.conceptref =
+ local.space
>> (*(cl::anychar_p -
- (']' | hard_space))) [actions.conceptref_pre]
- >> hard_space
+ (']' | local.hard_space))) [actions.conceptref_pre]
+ >> local.hard_space
>> phrase [actions.conceptref_post]
;
- globalref =
- space
+ local.globalref =
+ local.space
>> (*(cl::anychar_p -
- (']' | hard_space))) [actions.globalref_pre]
- >> hard_space
+ (']' | local.hard_space))) [actions.globalref_pre]
+ >> local.hard_space
>> phrase [actions.globalref_post]
;
phrase_symbol_rules.add
- ("*", &bold)
- ("'", &italic)
- ("_", &underline)
- ("^", &teletype)
- ("-", &strikethrough)
- ("\"", "e)
- ("~", &replaceable)
+ ("*", &local.bold)
+ ("'", &local.italic)
+ ("_", &local.underline)
+ ("^", &local.teletype)
+ ("-", &local.strikethrough)
+ ("\"", &local.quote)
+ ("~", &local.replaceable)
;
- bold =
- blank [actions.bold_pre]
+ local.bold =
+ local.blank [actions.bold_pre]
>> phrase [actions.bold_post]
;
- italic =
- blank [actions.italic_pre]
+ local.italic =
+ local.blank [actions.italic_pre]
>> phrase [actions.italic_post]
;
- underline =
- blank [actions.underline_pre]
+ local.underline =
+ local.blank [actions.underline_pre]
>> phrase [actions.underline_post]
;
- teletype =
- blank [actions.teletype_pre]
+ local.teletype =
+ local.blank [actions.teletype_pre]
>> phrase [actions.teletype_post]
;
- strikethrough =
- blank [actions.strikethrough_pre]
+ local.strikethrough =
+ local.blank [actions.strikethrough_pre]
>> phrase [actions.strikethrough_post]
;
- quote =
- blank [actions.quote_pre]
+ local.quote =
+ local.blank [actions.quote_pre]
>> phrase [actions.quote_post]
;
- replaceable =
- blank [actions.replaceable_pre]
+ local.replaceable =
+ local.blank [actions.replaceable_pre]
>> phrase [actions.replaceable_post]
;
phrase_keyword_rules.add
- ("c++", &source_mode_cpp)
- ("python", &source_mode_python)
- ("teletype", &source_mode_teletype)
+ ("c++", &local.source_mode_cpp)
+ ("python", &local.source_mode_python)
+ ("teletype", &local.source_mode_teletype)
;
- source_mode_cpp = cl::eps_p [cl::assign_a(actions.source_mode, "c++")];
- source_mode_python = cl::eps_p [cl::assign_a(actions.source_mode, "python")];
- source_mode_teletype = cl::eps_p [cl::assign_a(actions.source_mode, "teletype")];
+ local.source_mode_cpp = cl::eps_p [cl::assign_a(actions.source_mode, "c++")];
+ local.source_mode_python = cl::eps_p [cl::assign_a(actions.source_mode, "python")];
+ local.source_mode_teletype = cl::eps_p [cl::assign_a(actions.source_mode, "teletype")];
phrase_keyword_rules.add
- ("footnote", &footnote)
+ ("footnote", &local.footnote)
;
- footnote =
- blank [actions.footnote_pre]
+ local.footnote =
+ local.blank [actions.footnote_pre]
>> phrase [actions.footnote_post]
;
- }
- template <typename Scanner>
- struct simple_phrase_grammar::definition
- {
- definition(simple_phrase_grammar const& self)
- : unused(false), common(self.actions, unused)
- {
- quickbook::actions& actions = self.actions;
-
- phrase =
- *( common
- | comment
- | (cl::anychar_p - ']') [actions.plain_char]
- )
- ;
+ //
+ // Simple phrase grammar
+ //
- comment =
- "[/" >> *(dummy_block | (cl::anychar_p - ']')) >> ']'
- ;
-
- dummy_block =
- '[' >> *(dummy_block | (cl::anychar_p - ']')) >> ']'
- ;
- }
-
- bool unused;
- cl::rule<Scanner> phrase, comment, dummy_block;
- phrase_grammar common;
-
- cl::rule<Scanner> const&
- start() const { return phrase; }
- };
+ simple_phrase =
+ *( common
+ | local.comment
+ | (cl::anychar_p - ']') [actions.plain_char]
+ )
+ ;
- template <typename Scanner>
- struct command_line_grammar::definition
- {
- definition(command_line_grammar const& self)
- : unused(false), common(self.actions, unused)
- {
- quickbook::actions& actions = self.actions;
-
- macro =
- *cl::space_p
- >> macro_identifier [actions.macro_identifier]
+ //
+ // Command line
+ //
+
+ command_line =
+ *cl::space_p
+ >> local.command_line_macro_identifier
+ [actions.macro_identifier]
+ >> *cl::space_p
+ >> ( '='
+ >> *cl::space_p
+ >> local.command_line_phrase
+ [actions.macro_definition]
>> *cl::space_p
- >> ( '='
- >> *cl::space_p
- >> phrase [actions.macro_definition]
- >> *cl::space_p
- )
- | cl::eps_p [actions.macro_definition]
- ;
-
- macro_identifier =
- +(cl::anychar_p - (cl::space_p | ']' | '='))
- ;
-
- phrase =
- *( common
- | (cl::anychar_p - ']') [actions.plain_char]
)
- ;
- }
-
- bool unused;
- cl::rule<Scanner> macro, macro_identifier, phrase;
- phrase_grammar common;
+ | cl::eps_p [actions.macro_definition]
+ ;
- cl::rule<Scanner> const&
- start() const { return macro; }
- };
+ local.command_line_macro_identifier =
+ +(cl::anychar_p - (cl::space_p | ']' | '='))
+ ;
- cl::parse_info<iterator> call_parse(
- iterator& first, iterator last, phrase_grammar& g)
- {
- return boost::spirit::classic::parse(first, last, g);
- }
- cl::parse_info<iterator> call_parse(
- iterator& first, iterator last, simple_phrase_grammar& g)
- {
- return boost::spirit::classic::parse(first, last, g);
- }
-
- cl::parse_info<iterator> call_parse(
- iterator& first, iterator last, command_line_grammar& g)
- {
- return boost::spirit::classic::parse(first, last, g);
+ local.command_line_phrase =
+ *( common
+ | (cl::anychar_p - ']') [actions.plain_char]
+ )
+ ;
}
-
- // Explicitly instantiate phrase_grammar definition so that it can be
- // used in other grammars.
- template phrase_grammar::definition<scanner>::definition(
- phrase_grammar const& self);
}
Deleted: trunk/tools/quickbook/src/phrase_grammar.hpp
==============================================================================
--- trunk/tools/quickbook/src/phrase_grammar.hpp 2010-12-19 08:29:25 EST (Sun, 19 Dec 2010)
+++ (empty file)
@@ -1,51 +0,0 @@
-/*=============================================================================
- Copyright (c) 2002 2004 2006 Joel de Guzman
- Copyright (c) 2004 Eric Niebler
- http://spirit.sourceforge.net/
-
- Use, modification and distribution is subject to the Boost Software
- License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-#if !defined(BOOST_SPIRIT_QUICKBOOK_PHRASE_HPP)
-#define BOOST_SPIRIT_QUICKBOOK_PHRASE_HPP
-
-#include "grammar.hpp"
-#include <boost/spirit/include/classic_symbols.hpp>
-
-namespace quickbook
-{
- namespace cl = boost::spirit::classic;
-
- template <typename Scanner>
- struct phrase_grammar::definition
- {
- definition(phrase_grammar const& self);
-
- cl::rule<Scanner>
- space, blank, comment, phrase, phrase_markup, image,
- simple_phrase_end, 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, template_,
- source_mode_cpp, source_mode_python, source_mode_teletype,
- quote, code_block, footnote, replaceable, macro,
- dummy_block, cond_phrase, macro_identifier, template_args,
- template_args_1_4, template_arg_1_4,
- template_inner_arg_1_4, brackets_1_4,
- template_args_1_5, template_arg_1_5,
- template_inner_arg_1_5, brackets_1_5
- ;
-
- cl::symbols<cl::rule<Scanner>*> phrase_keyword_rules, phrase_symbol_rules;
- cl::rule<Scanner> phrase_keyword_rule;
-
- cl::rule<Scanner> const&
- start() const { return common; }
- };
-}
-
-#endif // BOOST_SPIRIT_QUICKBOOK_PHRASE_HPP
-
Modified: trunk/tools/quickbook/src/quickbook.cpp
==============================================================================
--- trunk/tools/quickbook/src/quickbook.cpp (original)
+++ trunk/tools/quickbook/src/quickbook.cpp 2010-12-19 08:29:25 EST (Sun, 19 Dec 2010)
@@ -44,7 +44,7 @@
static void set_macros(actions& actor)
{
- quickbook::command_line_grammar grammar(actor);
+ quickbook_grammar g(actor);
for(std::vector<std::string>::const_iterator
it = preset_defines.begin(),
@@ -54,7 +54,7 @@
iterator first(it->begin(), it->end(), "command line parameter");
iterator last(it->end(), it->end());
- call_parse(first, last, grammar);
+ cl::parse(first, last, g.command_line_macro);
// TODO: Check result?
}
}
@@ -81,15 +81,14 @@
iterator first(storage.begin(), storage.end(), filein_);
iterator last(storage.end(), storage.end());
- doc_info_grammar l(actor);
- cl::parse_info<iterator> info = call_parse(first, last, l);
+ quickbook_grammar g(actor);
+ cl::parse_info<iterator> info = cl::parse(first, last, g.doc_info);
if (info.hit || ignore_docinfo)
{
pre(actor.out, actor, ignore_docinfo);
- block_grammar g(actor);
- info = call_parse(info.hit ? info.stop : first, last, g);
+ info = cl::parse(info.hit ? info.stop : first, last, g.block);
if (info.full)
{
post(actor.out, actor, ignore_docinfo);
Added: trunk/tools/quickbook/src/rule_store.hpp
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/src/rule_store.hpp 2010-12-19 08:29:25 EST (Sun, 19 Dec 2010)
@@ -0,0 +1,83 @@
+/*=============================================================================
+ Copyright (c) 2010 Daniel James
+
+ Use, modification and distribution is subject to the Boost Software
+ License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+
+// This header defines a class which can will manage quickbook rules for a
+// grammar class so that it doesn't have to declare every rule it'll use.
+//
+// TODO: Noncopyable, but some sort of reference counting scheme would work.
+
+#if !defined(BOOST_SPIRIT_QUICKBOOK_RULE_STORE_HPP)
+#define BOOST_SPIRIT_QUICKBOOK_RULE_STORE_HPP
+
+#include <deque>
+#include <boost/assert.hpp>
+#include <utility>
+
+namespace quickbook
+{
+ namespace detail
+ {
+ template <typename T>
+ void delete_impl(void* ptr) {
+ delete static_cast<T*>(ptr);
+ }
+
+ struct scoped_void
+ {
+ void* ptr_;
+ void (*del_)(void*);
+
+ scoped_void() : ptr_(0), del_(0) {}
+ scoped_void(scoped_void const& src) : ptr_(0), del_(0) {
+ BOOST_ASSERT(!src.ptr_);
+ }
+ ~scoped_void() {
+ if(ptr_) del_(ptr_);
+ }
+
+ void store(void* ptr, void (*del)(void* x)) {
+ ptr = ptr_;
+ del = del_;
+ }
+ private:
+ scoped_void& operator=(scoped_void const&);
+ };
+ }
+
+ struct rule_store
+ {
+ struct instantiate
+ {
+ rule_store& s;
+ instantiate(rule_store& s) : s(s) {}
+
+ template <typename T>
+ operator T&() {
+ std::auto_ptr<T> obj(new T());
+ T& ref = *obj;
+ s.store_.push_back(detail::scoped_void());
+ s.store_.back().store(obj.release(), &detail::delete_impl<T>);
+ return ref;
+ }
+ };
+
+ rule_store() {}
+
+ instantiate create() {
+ instantiate i(*this);
+ return i;
+ }
+
+ std::deque<detail::scoped_void> store_;
+ private:
+ rule_store& operator=(rule_store const&);
+ rule_store(rule_store const&);
+ };
+}
+
+#endif
Modified: trunk/tools/quickbook/src/scoped_block.hpp
==============================================================================
--- trunk/tools/quickbook/src/scoped_block.hpp (original)
+++ trunk/tools/quickbook/src/scoped_block.hpp 2010-12-19 08:29:25 EST (Sun, 19 Dec 2010)
@@ -17,8 +17,7 @@
#ifndef BOOST_QUICKBOOK_SCOPED_BLOCK_HPP
#define BOOST_QUICKBOOK_SCOPED_BLOCK_HPP
-#include <boost/spirit/home/classic/namespace.hpp>
-#include <boost/spirit/home/classic/core/composite/composite.hpp>
+#include <boost/spirit/include/classic_core.hpp>
#include "actions_class.hpp"
namespace quickbook {
Modified: trunk/tools/quickbook/src/syntax_highlight.hpp
==============================================================================
--- trunk/tools/quickbook/src/syntax_highlight.hpp (original)
+++ trunk/tools/quickbook/src/syntax_highlight.hpp 2010-12-19 08:29:25 EST (Sun, 19 Dec 2010)
@@ -15,7 +15,7 @@
#include <boost/spirit/include/classic_chset.hpp>
#include <boost/spirit/include/classic_symbols.hpp>
#include <boost/spirit/include/classic_loops.hpp>
-#include "phrase_grammar.hpp"
+#include "grammar.hpp"
namespace quickbook
{
@@ -41,8 +41,7 @@
struct definition
{
definition(cpp_highlight const& self)
- : common(self.escape_actions, unused)
- , unused(false)
+ : g(self.escape_actions)
{
program
=
@@ -70,7 +69,7 @@
;
qbk_phrase =
- *( common
+ *( g.common
| (cl::anychar_p - cl::str_p("``"))
[self.escape_actions.plain_char]
)
@@ -158,9 +157,8 @@
string_char;
cl::symbols<> keyword_;
- phrase_grammar common;
+ quickbook_grammar g;
std::string save;
- bool unused;
cl::rule<Scanner> const&
start() const { return program; }
@@ -194,8 +192,7 @@
struct definition
{
definition(python_highlight const& self)
- : common(self.escape_actions, unused)
- , unused(false)
+ : g(self.escape_actions)
{
program
=
@@ -221,7 +218,7 @@
;
qbk_phrase =
- *( common
+ *( g.common
| (cl::anychar_p - cl::str_p("``"))
[self.escape_actions.plain_char]
)
@@ -316,9 +313,8 @@
qbk_phrase, escape, string_char;
cl::symbols<> keyword_;
- phrase_grammar common;
+ quickbook_grammar g;
std::string save;
- bool unused;
cl::rule<Scanner> const&
start() const { return program; }
@@ -348,8 +344,7 @@
struct definition
{
definition(teletype_highlight const& self)
- : common(self.escape_actions, unused)
- , unused(false)
+ : g(self.escape_actions)
{
program
=
@@ -367,7 +362,7 @@
;
qbk_phrase =
- *( common
+ *( g.common
| (cl::anychar_p - cl::str_p("``"))
[self.escape_actions.plain_char]
)
@@ -395,9 +390,8 @@
cl::rule<Scanner> program, macro, qbk_phrase, escape;
- phrase_grammar common;
+ quickbook_grammar g;
std::string save;
- bool unused;
cl::rule<Scanner> const&
start() const { return program; }
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