$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r69189 - in branches/quickbook-filenames/tools/quickbook: src test
From: dnljms_at_[hidden]
Date: 2011-02-22 16:28:51
Author: danieljames
Date: 2011-02-22 16:28:49 EST (Tue, 22 Feb 2011)
New Revision: 69189
URL: http://svn.boost.org/trac/boost/changeset/69189
Log:
More nestable elements. Refs #1193
Text files modified: 
   branches/quickbook-filenames/tools/quickbook/src/block_element_grammar.cpp |    38 +++++++++++-----------                  
   branches/quickbook-filenames/tools/quickbook/src/grammar_impl.hpp          |     9 +++-                                    
   branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp          |    60 ++++++++++++++++++++++++++++++------    
   branches/quickbook-filenames/tools/quickbook/src/syntax_highlight.hpp      |    27 +++++++++++-----                        
   branches/quickbook-filenames/tools/quickbook/test/table_1_5.gold           |    65 ++++++++++++++++++++++++++++++++++++++++
   branches/quickbook-filenames/tools/quickbook/test/table_1_5.quickbook      |    24 ++++++++++++++                          
   6 files changed, 181 insertions(+), 42 deletions(-)
Modified: branches/quickbook-filenames/tools/quickbook/src/block_element_grammar.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/block_element_grammar.cpp	(original)
+++ branches/quickbook-filenames/tools/quickbook/src/block_element_grammar.cpp	2011-02-22 16:28:49 EST (Tue, 22 Feb 2011)
@@ -88,27 +88,27 @@
             ;
 
         elements.add
-            ("heading", element_info(element_info::block, &local.heading, block_tags::generic_heading))
-            ("h1", element_info(element_info::block, &local.heading, block_tags::heading1))
-            ("h2", element_info(element_info::block, &local.heading, block_tags::heading2))
-            ("h3", element_info(element_info::block, &local.heading, block_tags::heading3))
-            ("h4", element_info(element_info::block, &local.heading, block_tags::heading4))
-            ("h5", element_info(element_info::block, &local.heading, block_tags::heading5))
-            ("h6", element_info(element_info::block, &local.heading, block_tags::heading6))
+            ("heading", element_info(element_info::conditional_or_block, &local.heading, block_tags::generic_heading))
+            ("h1", element_info(element_info::conditional_or_block, &local.heading, block_tags::heading1))
+            ("h2", element_info(element_info::conditional_or_block, &local.heading, block_tags::heading2))
+            ("h3", element_info(element_info::conditional_or_block, &local.heading, block_tags::heading3))
+            ("h4", element_info(element_info::conditional_or_block, &local.heading, block_tags::heading4))
+            ("h5", element_info(element_info::conditional_or_block, &local.heading, block_tags::heading5))
+            ("h6", element_info(element_info::conditional_or_block, &local.heading, block_tags::heading6))
             ;
 
         elements.add
-            ("blurb", element_info(element_info::block, &local.inner_block, block_tags::blurb))
-            (":", element_info(element_info::block, &local.inner_block, block_tags::blockquote))
-            ("warning", element_info(element_info::block, &local.inner_block, block_tags::warning))
-            ("caution", element_info(element_info::block, &local.inner_block, block_tags::caution))
-            ("important", element_info(element_info::block, &local.inner_block, block_tags::important))
-            ("note", element_info(element_info::block, &local.inner_block, block_tags::note))
-            ("tip", element_info(element_info::block, &local.inner_block, block_tags::tip))
+            ("blurb", element_info(element_info::nested_block, &local.inner_block, block_tags::blurb))
+            (":", element_info(element_info::nested_block, &local.inner_block, block_tags::blockquote))
+            ("warning", element_info(element_info::nested_block, &local.inner_block, block_tags::warning))
+            ("caution", element_info(element_info::nested_block, &local.inner_block, block_tags::caution))
+            ("important", element_info(element_info::nested_block, &local.inner_block, block_tags::important))
+            ("note", element_info(element_info::nested_block, &local.inner_block, block_tags::note))
+            ("tip", element_info(element_info::nested_block, &local.inner_block, block_tags::tip))
             ;
 
         elements.add
-            ("pre", element_info(element_info::block, &local.preformatted, block_tags::preformatted))
+            ("pre", element_info(element_info::nested_block, &local.preformatted, block_tags::preformatted))
             ;
 
         local.preformatted =
@@ -120,7 +120,7 @@
             ;
 
         elements.add
-            ("def", element_info(element_info::block, &local.def_macro, block_tags::macro_definition))
+            ("def", element_info(element_info::conditional_or_block, &local.def_macro, block_tags::macro_definition))
             ;
 
         local.def_macro =
@@ -139,7 +139,7 @@
             ;
 
         elements.add
-            ("template", element_info(element_info::block, &local.template_, block_tags::template_definition))
+            ("template", element_info(element_info::conditional_or_block, &local.template_, block_tags::template_definition))
             ;
 
         local.template_ =
@@ -168,7 +168,7 @@
             ;
 
         elements.add
-            ("variablelist", element_info(element_info::block, &local.variablelist, block_tags::variable_list))
+            ("variablelist", element_info(element_info::nested_block, &local.variablelist, block_tags::variable_list))
             ;
 
         local.variablelist =
@@ -206,7 +206,7 @@
             ;
 
         elements.add
-            ("table", element_info(element_info::block, &local.table, block_tags::table))
+            ("table", element_info(element_info::nested_block, &local.table, block_tags::table))
             ;
 
         local.table =
Modified: branches/quickbook-filenames/tools/quickbook/src/grammar_impl.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/grammar_impl.hpp	(original)
+++ branches/quickbook-filenames/tools/quickbook/src/grammar_impl.hpp	2011-02-22 16:28:49 EST (Tue, 22 Feb 2011)
@@ -26,12 +26,15 @@
             in_block = 1,
             in_phrase = 2,
             in_conditional = 4,
+            in_nested_block = 8
         };
 
         enum type_enum {
-            block = 1,
-            phrase = 2,
-            conditional_or_block = 5
+            nothing = 0,
+            block = in_block,
+            conditional_or_block = block | in_conditional,
+            nested_block = conditional_or_block | in_nested_block,
+            phrase = nested_block | in_phrase
         };
 
         element_info(
Modified: branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp	(original)
+++ branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp	2011-02-22 16:28:49 EST (Tue, 22 Feb 2011)
@@ -94,7 +94,7 @@
                 // be overridden by nested markup.
                 element_type_ = l.element_type;
 
-                if (element_type_ & element_info::block)
+                if (!(element_type_ & element_info::in_phrase))
                     l.actions_.paragraph();
 
                 l.actions_.values.reset()();
@@ -105,7 +105,7 @@
             template <typename ResultT, typename ScannerT>
             bool result(ResultT result, ScannerT const& scan)
             {
-                if (result || !(l.element_type & element_info::block))
+                if (result || l.element_type & element_info::in_phrase)
                     return result;
 
                 l.actions_.error(scan.first, scan.first);
@@ -113,11 +113,29 @@
             }
 
             void success() { l.element_type = element_type_; }
-            void failure() { l.element_type = element_type_; }
+            void failure() { l.element_type = element_info::nothing; }
 
             main_grammar_local& l;
             element_info::type_enum element_type_;
         };
+        
+        struct is_block_type
+        {
+            typedef bool result_type;
+            template <typename Arg1 = void>
+            struct result { typedef bool type; };
+        
+            is_block_type(main_grammar_local& l)
+                : l_(l)
+            {}
+
+            bool operator()() const
+            {
+                return !(l_.element_type & element_info::in_phrase);
+            }
+            
+            main_grammar_local& l_;
+        };
 
         cl::rule<scanner>
                         top_level, blocks, paragraph_separator,
@@ -146,11 +164,13 @@
         quickbook::actions& actions_;
         assign_element_type assign_element;
         scoped_parser<process_element_impl> process_element;
+        is_block_type is_block;
 
         main_grammar_local(quickbook::actions& actions)
             : actions_(actions)
             , assign_element(*this)
             , process_element(*this)
+            , is_block(*this)
             {}
     };
 
@@ -172,7 +192,9 @@
             actions.scoped_context(element_info::in_block)
             [   local.blocks
             >>  *(  local.element
-                >>  !(+eol >> local.blocks)
+                >>  cl::if_p(local.is_block)
+                    [   !(+eol >> local.blocks)
+                    ]
                 |   local.paragraph_separator >> local.blocks
                 |   common
                 |   cl::space_p                 [actions.space_char]
@@ -248,6 +270,8 @@
             ;
 
         local.list_item =
+            actions.scoped_context(element_info::in_phrase)
+            [
             actions.values.save()
             [
                 *(  common
@@ -258,12 +282,12 @@
                     )                       [actions.plain_char]
                 )
             ]
+            ]
             >> +eol
             ;
 
         common =
-            actions.scoped_context(element_info::in_phrase)
-            [   local.macro
+                local.macro
             |   local.element
             |   local.template_
             |   local.break_
@@ -272,7 +296,6 @@
             |   local.simple_format
             |   local.escape
             |   comment
-            ]
             ;
 
         local.macro =
@@ -409,26 +432,32 @@
             '=', actions.simple_teletype, local.simple_phrase_end);
 
         phrase =
+            actions.scoped_context(element_info::in_phrase)
+            [
             actions.values.save()
             [   *(  common
                 |   (cl::anychar_p - phrase_end)
                                                 [actions.plain_char]
                 )
             ]
+            ]
             ;
 
         extended_phrase =
+            actions.scoped_context(element_info::in_conditional)
+            [
             actions.values.save()
-            [  *(   actions.scoped_context(element_info::in_conditional)
-                    [ local.element ]
-                |   common
+            [  *(   common
                 |   (cl::anychar_p - phrase_end)
                                                 [actions.plain_char]
                 )
             ]
+            ]
             ;
 
         inside_paragraph =
+            actions.scoped_context(element_info::in_nested_block)
+            [
             actions.values.save()
             [   *(  local.paragraph_separator   [actions.paragraph]
                 |   common
@@ -436,6 +465,7 @@
                                                 [actions.plain_char]
                 )
             ]                                   [actions.paragraph]
+            ]
             ;
 
         local.escape =
@@ -457,11 +487,16 @@
         // Simple phrase grammar
         //
 
-        simple_phrase = actions.values.save()[
+        simple_phrase =
+            actions.scoped_context(element_info::in_phrase)
+            [
+            actions.values.save()
+            [
            *(   common
             |   (cl::anychar_p - ']')           [actions.plain_char]
             )
             ]
+            ]
             ;
 
         //
@@ -489,11 +524,14 @@
 
 
         local.command_line_phrase =
+            actions.scoped_context(element_info::in_phrase)
+            [
             actions.values.save()
             [   *(   common
                 |   (cl::anychar_p - ']')       [actions.plain_char]
                 )
             ]
+            ]
             ;
 
         // Miscellaneous stuff
Modified: branches/quickbook-filenames/tools/quickbook/src/syntax_highlight.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/syntax_highlight.hpp	(original)
+++ branches/quickbook-filenames/tools/quickbook/src/syntax_highlight.hpp	2011-02-22 16:28:49 EST (Tue, 22 Feb 2011)
@@ -16,6 +16,7 @@
 #include <boost/spirit/include/classic_symbols.hpp>
 #include <boost/spirit/include/classic_loops.hpp>
 #include "grammar.hpp"
+#include "grammar_impl.hpp" // Just for context stuff. Should move?
 
 namespace quickbook
 {
@@ -69,10 +70,12 @@
                     ;
 
                 qbk_phrase =
-                   *(   g.common
-                    |   (cl::anychar_p - cl::str_p("``"))
+                    self.escape_actions.scoped_context(element_info::in_phrase)
+                    [  *(   g.common
+                        |   (cl::anychar_p - cl::str_p("``"))
                                         [self.escape_actions.plain_char]
-                    )
+                        )
+                    ]
                     ;
 
                 escape =
@@ -218,10 +221,13 @@
                     ;
 
                 qbk_phrase =
-                   *(   g.common
-                    |   (cl::anychar_p - cl::str_p("``"))
+                    self.escape_actions.scoped_context(element_info::in_phrase)
+                    [
+                       *(   g.common
+                        |   (cl::anychar_p - cl::str_p("``"))
                                         [self.escape_actions.plain_char]
-                    )
+                        )
+                    ]
                     ;
 
                 escape =
@@ -362,10 +368,13 @@
                     ;
 
                 qbk_phrase =
-                   *(   g.common
-                    |   (cl::anychar_p - cl::str_p("``"))
+                    self.escape_actions.scoped_context(element_info::in_phrase)
+                    [
+                       *(   g.common
+                        |   (cl::anychar_p - cl::str_p("``"))
                                         [self.escape_actions.plain_char]
-                    )
+                        )
+                    ]
                     ;
 
                 escape =
Modified: branches/quickbook-filenames/tools/quickbook/test/table_1_5.gold
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/test/table_1_5.gold	(original)
+++ branches/quickbook-filenames/tools/quickbook/test/table_1_5.gold	2011-02-22 16:28:49 EST (Tue, 22 Feb 2011)
@@ -233,5 +233,70 @@
         </tbody>
       </tgroup>
     </table>
+    <table frame="all" id="table_1_5.section1.nested_tables">
+      <title>Nested Tables</title>
+      <tgroup cols="1">
+        <thead>
+          <row>
+            <entry>
+              <para>
+                Header 1
+              </para>
+            </entry>
+            <entry>
+              <para>
+                Header 2
+              </para>
+            </entry>
+          </row>
+        </thead>
+        <tbody>
+          <row>
+            <entry>
+              <table frame="all" id="table_1_5.section1.inner_table">
+                <title>Inner Table</title>
+                <tgroup cols="2">
+                  <thead>
+                    <row>
+                      <entry>
+                        <para>
+                          1.1
+                        </para>
+                      </entry>
+                      <entry>
+                        <para>
+                          1.2
+                        </para>
+                      </entry>
+                    </row>
+                  </thead>
+                  <tbody>
+                    <row>
+                      <entry>
+                        <para>
+                          2.1
+                        </para>
+                      </entry>
+                      <entry>
+                        <para>
+                          2.2
+                        </para>
+                      </entry>
+                    </row>
+                  </tbody>
+                </tgroup>
+              </table>
+            </entry>
+          </row>
+          <row>
+            <entry>
+              <para>
+                Something.
+              </para>
+            </entry>
+          </row>
+        </tbody>
+      </tgroup>
+    </table>
   </section>
 </article>
Modified: branches/quickbook-filenames/tools/quickbook/test/table_1_5.quickbook
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/test/table_1_5.quickbook	(original)
+++ branches/quickbook-filenames/tools/quickbook/test/table_1_5.quickbook	2011-02-22 16:28:49 EST (Tue, 22 Feb 2011)
@@ -69,4 +69,28 @@
   ]
 ]
 
+[table Nested Tables
+  [
+    [
+      Header 1
+    ]
+    [
+      Header 2
+    ]
+  ]
+  [
+    [
+      [table Inner Table
+        [[1.1][1.2]]
+        [[2.1][2.2]]
+      ]
+    ]
+  ]
+  [
+    [
+      Something.
+    ]
+  ]
+]
+
 [endsect]
\ No newline at end of file