|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r67325 - trunk/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2010-12-19 08:27:49
Author: danieljames
Date: 2010-12-19 08:27:48 EST (Sun, 19 Dec 2010)
New Revision: 67325
URL: http://svn.boost.org/trac/boost/changeset/67325
Log:
Use the Nabialek trick in quickbook.
Text files modified:
trunk/tools/quickbook/src/block_grammar.cpp | 180 ++++++++++++++++++++++++---------------
trunk/tools/quickbook/src/phrase_grammar.hpp | 156 ++++++++++++++++++++-------------
trunk/tools/quickbook/src/utils.hpp | 25 +++++
3 files changed, 231 insertions(+), 130 deletions(-)
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:27:48 EST (Sun, 19 Dec 2010)
@@ -31,9 +31,11 @@
bool no_eols;
cl::rule<Scanner>
- start_, blocks, block_markup, code, code_line, blank_line,
- paragraph, space, blank, comment, headings, h, h1, h2,
- h3, h4, h5, h6, hr, blurb, blockquote, admonition,
+ start_, 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,
+ warning, caution, important, note, tip,
inner_phrase, phrase, list, phrase_end, ordered_list, def_macro,
macro_identifier, table, table_row, variablelist,
varlistentry, varlistterm, varlistitem, table_cell,
@@ -46,6 +48,9 @@
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&
@@ -123,28 +128,22 @@
>> +eol
;
- block_markup =
- '[' >> space
- >> ( begin_section
- | end_section
- | headings
- | blurb
- | blockquote
- | admonition
- | preformatted
- | def_macro
- | table
- | variablelist
- | xinclude
- | include
- | import
- | template_
- )
+ block_markup
+ = block_markup_start
+ >> block_keyword_rule
>> ( (space >> ']' >> +eol)
| cl::eps_p [actions.error]
)
;
-
+
+ block_markup_start
+ = '[' >> space
+ >> ( block_keyword_rules [detail::assign_rule(block_keyword_rule)]
+ >> (cl::eps_p - (cl::alnum_p | '_'))
+ | block_symbol_rules [detail::assign_rule(block_keyword_rule)]
+ )
+ ;
+
element_id =
':'
>>
@@ -175,30 +174,40 @@
]
;
- begin_section =
- "section"
- >> hard_space
- >> element_id
- >> space
- >> inner_phrase [actions.begin_section]
+ block_keyword_rules.add
+ ("section", &begin_section)
+ ("endsect", &end_section)
;
- end_section =
- cl::str_p("endsect") [actions.end_section]
+ begin_section =
+ space
+ >> element_id
+ >> space
+ >> inner_phrase [actions.begin_section]
;
- headings =
- h1 | h2 | h3 | h4 | h5 | h6 | h
+ end_section =
+ cl::eps_p [actions.end_section]
;
- h = "heading" >> hard_space >> element_id_1_6 >> space >> inner_phrase [actions.h];
- h1 = "h1" >> hard_space >> element_id_1_6 >> space >> inner_phrase [actions.h1];
- h2 = "h2" >> hard_space >> element_id_1_6 >> space >> inner_phrase [actions.h2];
- h3 = "h3" >> hard_space >> element_id_1_6 >> space >> inner_phrase [actions.h3];
- h4 = "h4" >> hard_space >> element_id_1_6 >> space >> inner_phrase [actions.h4];
- h5 = "h5" >> hard_space >> element_id_1_6 >> space >> inner_phrase [actions.h5];
- h6 = "h6" >> hard_space >> element_id_1_6 >> space >> inner_phrase [actions.h6];
-
+ 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];
+
static const bool true_ = true;
static const bool false_ = false;
@@ -209,42 +218,61 @@
)
;
+ block_keyword_rules.add("blurb", &blurb);
+
blurb =
- "blurb" >> hard_space
- >> scoped_block(actions)[inside_paragraph]
+ scoped_block(actions)[inside_paragraph]
[actions.blurb]
;
+ block_symbol_rules.add
+ (":", &blockquote)
+ ;
+
blockquote =
- ':' >> blank >>
- scoped_block(actions)[inside_paragraph]
+ blank >> scoped_block(actions)[inside_paragraph]
[actions.blockquote]
;
- admonition =
- "warning" >> hard_space >>
+ block_keyword_rules.add
+ ("warning", &warning)
+ ("caution", &caution)
+ ("important", &important)
+ ("note", ¬e)
+ ("tip", &tip)
+ ;
+
+ warning =
scoped_block(actions)[inside_paragraph]
[actions.warning]
- |
- "caution" >> hard_space >>
+ ;
+
+ caution =
scoped_block(actions)[inside_paragraph]
[actions.caution]
- |
- "important" >> hard_space >>
+ ;
+
+ important =
scoped_block(actions)[inside_paragraph]
[actions.important]
- |
- "note" >> hard_space >>
+ ;
+
+ note =
scoped_block(actions)[inside_paragraph]
[actions.note]
- |
- "tip" >> hard_space >>
+ ;
+
+ tip =
scoped_block(actions)[inside_paragraph]
[actions.tip]
;
+ block_keyword_rules.add
+ ("pre", &preformatted)
+ ;
+
preformatted =
- "pre" >> hard_space [cl::assign_a(no_eols, false_)]
+ space [cl::assign_a(no_eols, false_)]
>> !eol >> phrase [actions.preformatted]
>> cl::eps_p [cl::assign_a(no_eols, true_)]
;
@@ -253,8 +281,12 @@
+(cl::anychar_p - (cl::space_p | ']'))
;
+ block_keyword_rules.add
+ ("def", &def_macro)
+ ;
+
def_macro =
- "def" >> hard_space
+ space
>> macro_identifier [actions.macro_identifier]
>> blank >> phrase [actions.macro_definition]
;
@@ -267,9 +299,12 @@
identifier | (cl::punct_p - (cl::ch_p('[') | ']'))
;
+ block_keyword_rules.add
+ ("template", &template_)
+ ;
+
template_ =
- "template"
- >> hard_space
+ space
>> template_id [cl::assign_a(actions.template_identifier)]
[cl::clear_a(actions.template_info)]
>>
@@ -293,9 +328,12 @@
>> space
;
+ block_keyword_rules.add
+ ("variablelist", &variablelist)
+ ;
+
variablelist =
- "variablelist"
- >> (cl::eps_p(*cl::blank_p >> cl::eol_p) | hard_space)
+ (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
@@ -348,10 +386,13 @@
)
;
+ block_keyword_rules.add
+ ("table", &table)
+ ;
+
table =
- "table"
- >> (cl::eps_p(*cl::blank_p >> cl::eol_p) | hard_space)
- >> element_id_1_5
+ (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]
@@ -385,23 +426,26 @@
)
;
+ block_keyword_rules.add
+ ("xinclude", &xinclude)
+ ("import", &import)
+ ("include", &include)
+ ;
+
xinclude =
- "xinclude"
- >> hard_space
+ space
>> (*(cl::anychar_p -
phrase_end)) [actions.xinclude]
;
import =
- "import"
- >> hard_space
+ space
>> (*(cl::anychar_p -
phrase_end)) [actions.import]
;
include =
- "include"
- >> hard_space
+ space
>>
!(
':'
Modified: trunk/tools/quickbook/src/phrase_grammar.hpp
==============================================================================
--- trunk/tools/quickbook/src/phrase_grammar.hpp (original)
+++ trunk/tools/quickbook/src/phrase_grammar.hpp 2010-12-19 08:27:48 EST (Sun, 19 Dec 2010)
@@ -71,7 +71,8 @@
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_,
+ 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,
@@ -80,6 +81,9 @@
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; }
};
@@ -268,30 +272,13 @@
)
;
- phrase_markup =
- '['
- >> ( cond_phrase
- | image
- | url
- | link
- | anchor
- | source_mode
- | funcref
- | classref
- | memberref
- | enumref
- | macroref
- | headerref
- | conceptref
- | globalref
- | bold
- | italic
- | underline
- | teletype
- | strikethrough
- | quote
- | replaceable
- | footnote
+ phrase_markup
+ = '['
+ >> ( phrase_keyword_rules [detail::assign_rule(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]
| cl::str_p("br") [actions.break_]
)
@@ -317,14 +304,22 @@
+(cl::anychar_p - (cl::space_p | ']'))
;
+ phrase_symbol_rules.add
+ ("?", &cond_phrase)
+ ;
+
cond_phrase =
- '?' >> blank
+ blank
>> macro_identifier [actions.cond_phrase_pre]
>> (!phrase) [actions.cond_phrase_post]
;
+ phrase_symbol_rules.add
+ ("$", &image)
+ ;
+
image =
- '$' >> blank [cl::clear_a(actions.attributes)]
+ blank [cl::clear_a(actions.attributes)]
>> cl::if_p(qbk_since(105u)) [
(+(
*cl::space_p
@@ -347,30 +342,51 @@
>> cl::eps_p(']') [actions.image]
;
+ phrase_symbol_rules.add
+ ("@", &url)
+ ;
+
url =
- '@'
- >> (*(cl::anychar_p -
+ (*(cl::anychar_p -
(']' | hard_space))) [actions.url_pre]
>> hard_space
>> phrase [actions.url_post]
;
+ phrase_keyword_rules.add
+ ("link", &link)
+ ;
+
link =
- "link" >> hard_space
+ space
>> (*(cl::anychar_p -
(']' | hard_space))) [actions.link_pre]
>> hard_space
>> phrase [actions.link_post]
;
+ phrase_symbol_rules.add
+ ("#", &anchor)
+ ;
+
anchor =
- "#"
- >> blank
+ blank
>> (*(cl::anychar_p - 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 =
- "funcref" >> hard_space
+ space
>> (*(cl::anychar_p -
(']' | hard_space))) [actions.funcref_pre]
>> hard_space
@@ -378,7 +394,7 @@
;
classref =
- "classref" >> hard_space
+ space
>> (*(cl::anychar_p -
(']' | hard_space))) [actions.classref_pre]
>> hard_space
@@ -386,7 +402,7 @@
;
memberref =
- "memberref" >> hard_space
+ space
>> (*(cl::anychar_p -
(']' | hard_space))) [actions.memberref_pre]
>> hard_space
@@ -394,7 +410,7 @@
;
enumref =
- "enumref" >> hard_space
+ space
>> (*(cl::anychar_p -
(']' | hard_space))) [actions.enumref_pre]
>> hard_space
@@ -402,7 +418,7 @@
;
macroref =
- "macroref" >> hard_space
+ space
>> (*(cl::anychar_p -
(']' | hard_space))) [actions.macroref_pre]
>> hard_space
@@ -410,7 +426,7 @@
;
headerref =
- "headerref" >> hard_space
+ space
>> (*(cl::anychar_p -
(']' | hard_space))) [actions.headerref_pre]
>> hard_space
@@ -418,7 +434,7 @@
;
conceptref =
- "conceptref" >> hard_space
+ space
>> (*(cl::anychar_p -
(']' | hard_space))) [actions.conceptref_pre]
>> hard_space
@@ -426,59 +442,75 @@
;
globalref =
- "globalref" >> hard_space
+ space
>> (*(cl::anychar_p -
(']' | hard_space))) [actions.globalref_pre]
>> hard_space
>> phrase [actions.globalref_post]
;
+ phrase_symbol_rules.add
+ ("*", &bold)
+ ("'", &italic)
+ ("_", &underline)
+ ("^", &teletype)
+ ("-", &strikethrough)
+ ("\"", "e)
+ ("~", &replaceable)
+ ;
+
bold =
- cl::ch_p('*') [actions.bold_pre]
- >> blank >> phrase [actions.bold_post]
+ blank [actions.bold_pre]
+ >> phrase [actions.bold_post]
;
italic =
- cl::ch_p('\'') [actions.italic_pre]
- >> blank >> phrase [actions.italic_post]
+ blank [actions.italic_pre]
+ >> phrase [actions.italic_post]
;
underline =
- cl::ch_p('_') [actions.underline_pre]
- >> blank >> phrase [actions.underline_post]
+ blank [actions.underline_pre]
+ >> phrase [actions.underline_post]
;
teletype =
- cl::ch_p('^') [actions.teletype_pre]
- >> blank >> phrase [actions.teletype_post]
+ blank [actions.teletype_pre]
+ >> phrase [actions.teletype_post]
;
strikethrough =
- cl::ch_p('-') [actions.strikethrough_pre]
- >> blank >> phrase [actions.strikethrough_post]
+ blank [actions.strikethrough_pre]
+ >> phrase [actions.strikethrough_post]
;
quote =
- cl::ch_p('"') [actions.quote_pre]
- >> blank >> phrase [actions.quote_post]
+ blank [actions.quote_pre]
+ >> phrase [actions.quote_post]
;
replaceable =
- cl::ch_p('~') [actions.replaceable_pre]
- >> blank >> phrase [actions.replaceable_post]
+ blank [actions.replaceable_pre]
+ >> phrase [actions.replaceable_post]
;
- source_mode =
- (
- cl::str_p("c++")
- | "python"
- | "teletype"
- ) [cl::assign_a(actions.source_mode)]
+ phrase_keyword_rules.add
+ ("c++", &source_mode_cpp)
+ ("python", &source_mode_python)
+ ("teletype", &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")];
+
+ phrase_keyword_rules.add
+ ("footnote", &footnote)
;
footnote =
- cl::str_p("footnote") [actions.footnote_pre]
- >> blank >> phrase [actions.footnote_post]
+ blank [actions.footnote_pre]
+ >> phrase [actions.footnote_post]
;
}
}
Modified: trunk/tools/quickbook/src/utils.hpp
==============================================================================
--- trunk/tools/quickbook/src/utils.hpp (original)
+++ trunk/tools/quickbook/src/utils.hpp 2010-12-19 08:27:48 EST (Sun, 19 Dec 2010)
@@ -51,6 +51,31 @@
return var_wrapper<T>(t);
}
+ template <typename Rule>
+ struct assign_rule_impl
+ {
+ assign_rule_impl(Rule& the_rule)
+ : m_the_rule(the_rule)
+ {
+ }
+
+ void operator()(Rule* new_rule) const
+ {
+ m_the_rule = *new_rule;
+ }
+
+ private:
+
+ Rule& m_the_rule;
+ };
+
+ template <typename Rule>
+ assign_rule_impl<Rule> assign_rule(Rule& the_rule)
+ {
+ return assign_rule_impl<Rule>(the_rule);
+ }
+
+
// un-indent a code segment
void unindent(std::string& 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