Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r68115 - in branches/release/tools/quickbook: src test
From: dnljms_at_[hidden]
Date: 2011-01-13 13:18:20


Author: danieljames
Date: 2011-01-13 13:18:18 EST (Thu, 13 Jan 2011)
New Revision: 68115
URL: http://svn.boost.org/trac/boost/changeset/68115

Log:
Merge quickbook from trunk.

- Use a single symbol table for all elements.
- Fix filesystem use on windows. Fixes #5055.

Properties modified:
   branches/release/tools/quickbook/src/ (props changed)
   branches/release/tools/quickbook/test/ (props changed)
Text files modified:
   branches/release/tools/quickbook/src/actions.cpp | 6 +-
   branches/release/tools/quickbook/src/actions_class.cpp | 2
   branches/release/tools/quickbook/src/block_element_grammar.cpp | 74 +++++++++++++++++--------------------
   branches/release/tools/quickbook/src/doc_info_actions.cpp | 8 ++--
   branches/release/tools/quickbook/src/grammar_impl.hpp | 31 +++++++++++----
   branches/release/tools/quickbook/src/main_grammar.cpp | 79 +++++++++++++++++++++++++++------------
   branches/release/tools/quickbook/src/phrase_element_grammar.cpp | 66 ++++++++++++++++----------------
   branches/release/tools/quickbook/src/utils.hpp | 25 ------------
   branches/release/tools/quickbook/test/cond_phrase.gold | 3 +
   branches/release/tools/quickbook/test/cond_phrase.quickbook | 4 +
   10 files changed, 159 insertions(+), 139 deletions(-)

Modified: branches/release/tools/quickbook/src/actions.cpp
==============================================================================
--- branches/release/tools/quickbook/src/actions.cpp (original)
+++ branches/release/tools/quickbook/src/actions.cpp 2011-01-13 13:18:18 EST (Thu, 13 Jan 2011)
@@ -157,7 +157,7 @@
         if(actions.suppress) return;
 
         int level_ = section_level + 2; // section_level is zero-based. We need to use a
- // 0ne-based heading which is one greater
+ // one-based heading which is one greater
                                             // than the current. Thus: section_level + 2.
         if (level_ > 6) // The max is h6, clip it if it goes
             level_ = 6; // further than that
@@ -1414,10 +1414,10 @@
         }
 
         // update the __FILENAME__ macro
- *boost::spirit::classic::find(actions.macro, "__FILENAME__") = actions.filename.native();
+ *boost::spirit::classic::find(actions.macro, "__FILENAME__") = actions.filename.string();
 
         // parse the file
- quickbook::parse_file(actions.filename.native().c_str(), actions, true);
+ quickbook::parse_file(actions.filename.string().c_str(), actions, true);
 
         // restore the values
         std::swap(actions.filename, filein);

Modified: branches/release/tools/quickbook/src/actions_class.cpp
==============================================================================
--- branches/release/tools/quickbook/src/actions_class.cpp (original)
+++ branches/release/tools/quickbook/src/actions_class.cpp 2011-01-13 13:18:18 EST (Thu, 13 Jan 2011)
@@ -206,7 +206,7 @@
         // turn off __FILENAME__ macro on debug mode = true
         std::string filename_str = debug_mode ?
             std::string("NO_FILENAME_MACRO_GENERATED_IN_DEBUG_MODE") :
- filename.native();
+ filename.string();
 
         // add the predefined macros
         macro.add

Modified: branches/release/tools/quickbook/src/block_element_grammar.cpp
==============================================================================
--- branches/release/tools/quickbook/src/block_element_grammar.cpp (original)
+++ branches/release/tools/quickbook/src/block_element_grammar.cpp 2011-01-13 13:18:18 EST (Thu, 13 Jan 2011)
@@ -70,9 +70,9 @@
                 ]
                 ;
 
- block_keyword_rules.add
- ("section", &local.begin_section)
- ("endsect", &local.end_section)
+ elements.add
+ ("section", element_info(element_info::block, &local.begin_section))
+ ("endsect", element_info(element_info::block, &local.end_section))
             ;
 
         local.begin_section =
@@ -86,14 +86,14 @@
                 cl::eps_p [actions.end_section]
             ;
 
- block_keyword_rules.add
- ("heading", &local.h)
- ("h1", &local.h1)
- ("h2", &local.h2)
- ("h3", &local.h3)
- ("h4", &local.h4)
- ("h5", &local.h5)
- ("h6", &local.h6)
+ elements.add
+ ("heading", element_info(element_info::block, &local.h))
+ ("h1", element_info(element_info::block, &local.h1))
+ ("h2", element_info(element_info::block, &local.h2))
+ ("h3", element_info(element_info::block, &local.h3))
+ ("h4", element_info(element_info::block, &local.h4))
+ ("h5", element_info(element_info::block, &local.h5))
+ ("h6", element_info(element_info::block, &local.h6))
             ;
 
         local.h = space >> local.element_id_1_6 >> space >> local.inner_phrase [actions.h];
@@ -107,15 +107,15 @@
         static const bool true_ = true;
         static const bool false_ = false;
 
- block_keyword_rules.add("blurb", &local.blurb);
+ elements.add("blurb", element_info(element_info::block, &local.blurb));
 
         local.blurb =
             actions.scoped_block[inside_paragraph]
                                                 [actions.blurb]
             ;
 
- block_symbol_rules.add
- (":", &local.blockquote)
+ elements.add
+ (":", element_info(element_info::block, &local.blockquote))
             ;
 
         local.blockquote =
@@ -123,12 +123,12 @@
                                                 [actions.blockquote]
             ;
 
- block_keyword_rules.add
- ("warning", &local.warning)
- ("caution", &local.caution)
- ("important", &local.important)
- ("note", &local.note)
- ("tip", &local.tip)
+ elements.add
+ ("warning", element_info(element_info::block, &local.warning))
+ ("caution", element_info(element_info::block, &local.caution))
+ ("important", element_info(element_info::block, &local.important))
+ ("note", element_info(element_info::block, &local.note))
+ ("tip", element_info(element_info::block, &local.tip))
             ;
 
         local.warning =
@@ -156,8 +156,8 @@
                                                 [actions.tip]
             ;
 
- block_keyword_rules.add
- ("pre", &local.preformatted)
+ elements.add
+ ("pre", element_info(element_info::block, &local.preformatted))
             ;
 
         local.preformatted =
@@ -166,8 +166,8 @@
>> actions.set_no_eols[phrase] [actions.preformatted]
             ;
 
- block_keyword_rules.add
- ("def", &local.def_macro)
+ elements.add
+ ("def", element_info(element_info::block, &local.def_macro))
             ;
 
         local.def_macro =
@@ -184,8 +184,8 @@
             local.identifier | (cl::punct_p - (cl::ch_p('[') | ']'))
             ;
 
- block_keyword_rules.add
- ("template", &local.template_)
+ elements.add
+ ("template", element_info(element_info::block, &local.template_))
             ;
 
         local.template_ =
@@ -214,8 +214,8 @@
>> space
             ;
 
- block_keyword_rules.add
- ("variablelist", &local.variablelist)
+ elements.add
+ ("variablelist", element_info(element_info::block, &local.variablelist))
             ;
 
         local.variablelist =
@@ -272,8 +272,8 @@
             )
             ;
 
- block_keyword_rules.add
- ("table", &local.table)
+ elements.add
+ ("table", element_info(element_info::block, &local.table))
             ;
 
         local.table =
@@ -312,16 +312,10 @@
                 )
             ;
 
- block_keyword_rules.add
- ("xinclude", &local.xinclude)
- ("import", &local.import)
- ("include", &local.include)
- ;
-
- extended_phrase_keyword_rules.add
- ("xinclude", &local.xinclude)
- ("import", &local.import)
- ("include", &local.include)
+ elements.add
+ ("xinclude", element_info(element_info::conditional_or_block, &local.xinclude))
+ ("import", element_info(element_info::conditional_or_block, &local.import))
+ ("include", element_info(element_info::conditional_or_block, &local.include))
             ;
 
         local.xinclude =

Modified: branches/release/tools/quickbook/src/doc_info_actions.cpp
==============================================================================
--- branches/release/tools/quickbook/src/doc_info_actions.cpp (original)
+++ branches/release/tools/quickbook/src/doc_info_actions.cpp 2011-01-13 13:18:18 EST (Thu, 13 Jan 2011)
@@ -77,7 +77,7 @@
             qbk_major_version = 1;
             qbk_minor_version = 1;
             qbk_version_n = 101;
- detail::outwarn(actions.filename.native(),1)
+ detail::outwarn(actions.filename.string(),1)
                 << "Warning: Quickbook version undefined. "
                 "Version 1.1 is assumed" << std::endl;
         }
@@ -89,13 +89,13 @@
         
         if (qbk_version_n == 106)
         {
- detail::outwarn(actions.filename.native(),1)
+ detail::outwarn(actions.filename.string(),1)
                 << "Quickbook 1.6 is still under development and is "
                 "likely to change in the future." << std::endl;
         }
         else if(qbk_version_n < 100 || qbk_version_n > 106)
         {
- detail::outerr(actions.filename.native(),1)
+ detail::outerr(actions.filename.string(),1)
                 << "Unknown version of quickbook: quickbook "
                 << qbk_major_version
                 << "."
@@ -121,7 +121,7 @@
 
             if(!invalid_attributes.empty())
             {
- detail::outwarn(actions.filename.native(),1)
+ detail::outwarn(actions.filename.string(),1)
                     << (invalid_attributes.size() > 1 ?
                         "Invalid attributes" : "Invalid attribute")
                     << " for '" << actions.doc_type << " document info': "

Modified: branches/release/tools/quickbook/src/grammar_impl.hpp
==============================================================================
--- branches/release/tools/quickbook/src/grammar_impl.hpp (original)
+++ branches/release/tools/quickbook/src/grammar_impl.hpp 2011-01-13 13:18:18 EST (Thu, 13 Jan 2011)
@@ -19,6 +19,27 @@
 {
     namespace cl = boost::spirit::classic;
 
+ struct element_info
+ {
+ enum context {
+ in_block = 1,
+ in_phrase = 2,
+ in_conditional = 4,
+ };
+
+ enum type_enum {
+ block = 1,
+ phrase = 2,
+ conditional_or_block = 5
+ };
+
+ element_info(type_enum t, cl::rule<scanner>* r)
+ : type(t), rule(r) {}
+
+ type_enum type;
+ cl::rule<scanner>* rule;
+ };
+
     struct quickbook_grammar::impl
     {
         quickbook::actions& actions;
@@ -43,14 +64,8 @@
         cl::rule<scanner> comment;
         cl::rule<scanner> macro_identifier;
 
- // Markup Symbols
- cl::symbols<cl::rule<scanner>*> phrase_keyword_rules;
- cl::symbols<cl::rule<scanner>*> phrase_symbol_rules;
-
- cl::symbols<cl::rule<scanner>*> block_keyword_rules;
- cl::symbols<cl::rule<scanner>*> block_symbol_rules;
-
- cl::symbols<cl::rule<scanner>*> extended_phrase_keyword_rules;
+ // Element Symbols
+ cl::symbols<element_info> elements;
         
         // Doc Info
         cl::rule<scanner> doc_info_details;

Modified: branches/release/tools/quickbook/src/main_grammar.cpp
==============================================================================
--- branches/release/tools/quickbook/src/main_grammar.cpp (original)
+++ branches/release/tools/quickbook/src/main_grammar.cpp 2011-01-13 13:18:18 EST (Thu, 13 Jan 2011)
@@ -60,10 +60,10 @@
     {
         cl::rule<scanner>
                         top_level, blocks, paragraph_separator,
- block_element, block_element_start,
+ block_element,
                         code, code_line, blank_line, hr,
                         list, ordered_list, list_item,
- phrase_element, extended_phrase_element,
+ phrase_element, extended_phrase_element, element,
                         simple_phrase_end,
                         escape,
                         inline_code, simple_format,
@@ -79,8 +79,39 @@
                         dummy_block
                         ;
 
- cl::rule<scanner> block_keyword_rule;
- cl::rule<scanner> phrase_keyword_rule;
+ struct assign_element_type {
+ assign_element_type(main_grammar_local& l) : l(l) {}
+
+ void operator()(element_info& t) const {
+ l.element_type = t.type;
+ l.element_rule = *t.rule;
+ }
+
+ main_grammar_local& l;
+ };
+
+ struct check_element_type {
+ check_element_type(main_grammar_local const& l, element_info::context t)
+ : l(l), t(t) {}
+
+ bool operator()() const {
+ return l.element_type & t;
+ }
+
+ main_grammar_local const& l;
+ element_info::context t;
+ };
+
+ element_info::type_enum element_type;
+ cl::rule<scanner> element_rule;
+ assign_element_type assign_element;
+
+ main_grammar_local()
+ : assign_element(*this) {}
+
+ check_element_type check_element(element_info::context t) const {
+ return check_element_type(*this, t);
+ }
     };
 
     void quickbook_grammar::impl::init_main()
@@ -128,22 +159,17 @@
             ;
 
         local.block_element
- = local.block_element_start [actions.inside_paragraph]
- >> ( local.block_keyword_rule
+ = '[' >> space
+ >> local.element
+ >> cl::eps_p(local.check_element(element_info::in_block))
+ [actions.inside_paragraph]
+ >> ( local.element_rule
>> ( (space >> ']')
                     | cl::eps_p [actions.error]
                     )
                 | cl::eps_p [actions.error]
                 )
             ;
-
- local.block_element_start
- = '[' >> space
- >> ( block_keyword_rules [detail::assign_rule(local.block_keyword_rule)]
- >> (cl::eps_p - (cl::alnum_p | '_'))
- | block_symbol_rules [detail::assign_rule(local.block_keyword_rule)]
- )
- ;
         
         local.code =
             (
@@ -344,11 +370,9 @@
         local.phrase_element
             = '['
>> space
- >> ( phrase_keyword_rules [detail::assign_rule(local.phrase_keyword_rule)]
- >> (cl::eps_p - (cl::alnum_p | '_'))
- >> local.phrase_keyword_rule
- | phrase_symbol_rules [detail::assign_rule(local.phrase_keyword_rule)]
- >> local.phrase_keyword_rule
+ >> ( local.element
+ >> cl::eps_p(local.check_element(element_info::in_phrase))
+ >> local.element_rule
                 | local.template_ [actions.do_template]
                 | cl::str_p("br") [actions.break_]
                 )
@@ -356,12 +380,11 @@
             ;
 
         local.extended_phrase_element
- = '['
- >> space
- >> extended_phrase_keyword_rules [detail::assign_rule(local.block_keyword_rule)]
- >> (cl::eps_p - (cl::alnum_p | '_'))
+ = '[' >> space
+ >> local.element
+ >> cl::eps_p(local.check_element(element_info::in_conditional))
                                                 [actions.inside_paragraph]
- >> ( local.block_keyword_rule
+ >> ( local.element_rule
>> ( (space >> ']')
                     | cl::eps_p [actions.error]
                     )
@@ -369,6 +392,14 @@
                 )
             ;
 
+
+ local.element
+ = cl::eps_p(cl::punct_p)
+ >> elements [local.assign_element]
+ | elements [local.assign_element]
+ >> (cl::eps_p - (cl::alnum_p | '_'))
+ ;
+
         local.escape =
                 cl::str_p("\\n") [actions.break_]
             | cl::str_p("\\ ") // ignore an escaped space

Modified: branches/release/tools/quickbook/src/phrase_element_grammar.cpp
==============================================================================
--- branches/release/tools/quickbook/src/phrase_element_grammar.cpp (original)
+++ branches/release/tools/quickbook/src/phrase_element_grammar.cpp 2011-01-13 13:18:18 EST (Thu, 13 Jan 2011)
@@ -40,8 +40,8 @@
 
         phrase_element_grammar_local& local = store_.create();
 
- phrase_symbol_rules.add
- ("?", &local.cond_phrase)
+ elements.add
+ ("?", element_info(element_info::phrase, &local.cond_phrase))
             ;
 
         local.cond_phrase =
@@ -50,8 +50,8 @@
>> actions.scoped_cond_phrase[extended_phrase]
             ;
 
- phrase_symbol_rules.add
- ("$", &local.image)
+ elements.add
+ ("$", element_info(element_info::phrase, &local.image))
             ;
 
         local.image =
@@ -78,8 +78,8 @@
>> cl::eps_p(']') [actions.image]
             ;
             
- phrase_symbol_rules.add
- ("@", &local.url)
+ elements.add
+ ("@", element_info(element_info::phrase, &local.url))
             ;
 
         local.url =
@@ -89,8 +89,8 @@
>> phrase [actions.url_post]
             ;
 
- phrase_keyword_rules.add
- ("link", &local.link)
+ elements.add
+ ("link", element_info(element_info::phrase, &local.link))
             ;
 
         local.link =
@@ -101,8 +101,8 @@
>> phrase [actions.link_post]
             ;
 
- phrase_symbol_rules.add
- ("#", &local.anchor)
+ elements.add
+ ("#", element_info(element_info::phrase, &local.anchor))
             ;
 
         local.anchor =
@@ -110,15 +110,15 @@
>> (*(cl::anychar_p - phrase_end)) [actions.anchor]
             ;
 
- phrase_keyword_rules.add
- ("funcref", &local.funcref)
- ("classref", &local.classref)
- ("memberref", &local.memberref)
- ("enumref", &local.enumref)
- ("macroref", &local.macroref)
- ("headerref", &local.headerref)
- ("conceptref", &local.conceptref)
- ("globalref", &local.globalref)
+ elements.add
+ ("funcref", element_info(element_info::phrase, &local.funcref))
+ ("classref", element_info(element_info::phrase, &local.classref))
+ ("memberref", element_info(element_info::phrase, &local.memberref))
+ ("enumref", element_info(element_info::phrase, &local.enumref))
+ ("macroref", element_info(element_info::phrase, &local.macroref))
+ ("headerref", element_info(element_info::phrase, &local.headerref))
+ ("conceptref", element_info(element_info::phrase, &local.conceptref))
+ ("globalref", element_info(element_info::phrase, &local.globalref))
             ;
 
         local.funcref =
@@ -185,14 +185,14 @@
>> phrase [actions.globalref_post]
             ;
 
- phrase_symbol_rules.add
- ("*", &local.bold)
- ("'", &local.italic)
- ("_", &local.underline)
- ("^", &local.teletype)
- ("-", &local.strikethrough)
- ("\"", &local.quote)
- ("~", &local.replaceable)
+ elements.add
+ ("*", element_info(element_info::phrase, &local.bold))
+ ("'", element_info(element_info::phrase, &local.italic))
+ ("_", element_info(element_info::phrase, &local.underline))
+ ("^", element_info(element_info::phrase, &local.teletype))
+ ("-", element_info(element_info::phrase, &local.strikethrough))
+ ("\"", element_info(element_info::phrase, &local.quote))
+ ("~", element_info(element_info::phrase, &local.replaceable))
             ;
 
         local.bold =
@@ -230,18 +230,18 @@
>> phrase [actions.replaceable_post]
             ;
 
- phrase_keyword_rules.add
- ("c++", &local.source_mode_cpp)
- ("python", &local.source_mode_python)
- ("teletype", &local.source_mode_teletype)
+ elements.add
+ ("c++", element_info(element_info::phrase, &local.source_mode_cpp))
+ ("python", element_info(element_info::phrase, &local.source_mode_python))
+ ("teletype", element_info(element_info::phrase, &local.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", &local.footnote)
+ elements.add
+ ("footnote", element_info(element_info::phrase, &local.footnote))
             ;
 
         local.footnote =

Modified: branches/release/tools/quickbook/src/utils.hpp
==============================================================================
--- branches/release/tools/quickbook/src/utils.hpp (original)
+++ branches/release/tools/quickbook/src/utils.hpp 2011-01-13 13:18:18 EST (Thu, 13 Jan 2011)
@@ -51,31 +51,6 @@
         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);
 

Modified: branches/release/tools/quickbook/test/cond_phrase.gold
==============================================================================
--- branches/release/tools/quickbook/test/cond_phrase.gold (original)
+++ branches/release/tools/quickbook/test/cond_phrase.gold 2011-01-13 13:18:18 EST (Thu, 13 Jan 2011)
@@ -9,4 +9,7 @@
   <para>
     The should be no space inserted.
   </para>
+ <para>
+ <emphasis role="bold">Bold text</emphasis>
+ </para>
 </article>

Modified: branches/release/tools/quickbook/test/cond_phrase.quickbook
==============================================================================
--- branches/release/tools/quickbook/test/cond_phrase.quickbook (original)
+++ branches/release/tools/quickbook/test/cond_phrase.quickbook 2011-01-13 13:18:18 EST (Thu, 13 Jan 2011)
@@ -7,4 +7,6 @@
 [? __defined__ This should show]
 [? __undefined__ This should not show]
 
-The should be no sp[?__undefined__ just some junk]ace inserted.
\ No newline at end of file
+The should be no sp[?__undefined__ just some junk]ace inserted.
+
+[? __defined__ [*Bold text]]
\ No newline at end of file


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