Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67855 - in trunk/tools/quickbook: src test
From: dnljms_at_[hidden]
Date: 2011-01-09 07:01:19


Author: danieljames
Date: 2011-01-09 07:01:15 EST (Sun, 09 Jan 2011)
New Revision: 67855
URL: http://svn.boost.org/trac/boost/changeset/67855

Log:
Use a single symbol table for all elements.
Text files modified:
   trunk/tools/quickbook/src/block_element_grammar.cpp | 74 +++++++++++++++++--------------------
   trunk/tools/quickbook/src/grammar_impl.hpp | 31 +++++++++++----
   trunk/tools/quickbook/src/main_grammar.cpp | 79 +++++++++++++++++++++++++++------------
   trunk/tools/quickbook/src/phrase_element_grammar.cpp | 66 ++++++++++++++++----------------
   trunk/tools/quickbook/src/utils.hpp | 25 ------------
   trunk/tools/quickbook/test/cond_phrase.gold | 3 +
   trunk/tools/quickbook/test/cond_phrase.quickbook | 4 +
   7 files changed, 151 insertions(+), 131 deletions(-)

Modified: trunk/tools/quickbook/src/block_element_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/block_element_grammar.cpp (original)
+++ trunk/tools/quickbook/src/block_element_grammar.cpp 2011-01-09 07:01:15 EST (Sun, 09 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: trunk/tools/quickbook/src/grammar_impl.hpp
==============================================================================
--- trunk/tools/quickbook/src/grammar_impl.hpp (original)
+++ trunk/tools/quickbook/src/grammar_impl.hpp 2011-01-09 07:01:15 EST (Sun, 09 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: trunk/tools/quickbook/src/main_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/main_grammar.cpp (original)
+++ trunk/tools/quickbook/src/main_grammar.cpp 2011-01-09 07:01:15 EST (Sun, 09 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: trunk/tools/quickbook/src/phrase_element_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/phrase_element_grammar.cpp (original)
+++ trunk/tools/quickbook/src/phrase_element_grammar.cpp 2011-01-09 07:01:15 EST (Sun, 09 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: trunk/tools/quickbook/src/utils.hpp
==============================================================================
--- trunk/tools/quickbook/src/utils.hpp (original)
+++ trunk/tools/quickbook/src/utils.hpp 2011-01-09 07:01:15 EST (Sun, 09 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: trunk/tools/quickbook/test/cond_phrase.gold
==============================================================================
--- trunk/tools/quickbook/test/cond_phrase.gold (original)
+++ trunk/tools/quickbook/test/cond_phrase.gold 2011-01-09 07:01:15 EST (Sun, 09 Jan 2011)
@@ -9,4 +9,7 @@
   <para>
     The should be no space inserted.
   </para>
+ <para>
+ <emphasis role="bold">Bold text</emphasis>
+ </para>
 </article>

Modified: trunk/tools/quickbook/test/cond_phrase.quickbook
==============================================================================
--- trunk/tools/quickbook/test/cond_phrase.quickbook (original)
+++ trunk/tools/quickbook/test/cond_phrase.quickbook 2011-01-09 07:01:15 EST (Sun, 09 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