$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r70189 - in trunk/tools/quickbook: . src test
From: dnljms_at_[hidden]
Date: 2011-03-19 11:19:11
Author: danieljames
Date: 2011-03-19 11:19:09 EDT (Sat, 19 Mar 2011)
New Revision: 70189
URL: http://svn.boost.org/trac/boost/changeset/70189
Log:
Quickbook: nestable elements. Refs #1193
Properties modified: 
   trunk/tools/quickbook/   (props changed)
Text files modified: 
   trunk/tools/quickbook/src/actions.cpp               |    25 +++                                     
   trunk/tools/quickbook/src/actions.hpp               |    19 ++                                      
   trunk/tools/quickbook/src/actions_class.cpp         |     1                                         
   trunk/tools/quickbook/src/actions_class.hpp         |     3                                         
   trunk/tools/quickbook/src/block_element_grammar.cpp |    38 +++---                                  
   trunk/tools/quickbook/src/grammar_impl.hpp          |     9 +                                       
   trunk/tools/quickbook/src/main_grammar.cpp          |   225 ++++++++++++++++++++++++--------------- 
   trunk/tools/quickbook/src/parsers.hpp               |    32 +++--                                   
   trunk/tools/quickbook/src/rule_store.hpp            |    10 +                                       
   trunk/tools/quickbook/src/scoped.hpp                |     8 +                                       
   trunk/tools/quickbook/src/syntax_highlight.hpp      |    27 +++-                                    
   trunk/tools/quickbook/src/values_parse.hpp          |    22 ++-                                     
   trunk/tools/quickbook/test/table_1_5.gold           |    65 +++++++++++                             
   trunk/tools/quickbook/test/table_1_5.quickbook      |    24 ++++                                    
   14 files changed, 360 insertions(+), 148 deletions(-)
Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp	(original)
+++ trunk/tools/quickbook/src/actions.cpp	2011-03-19 11:19:09 EDT (Sat, 19 Mar 2011)
@@ -329,7 +329,7 @@
         out << post;
     }
 
-    void cond_phrase_push::start()
+    bool cond_phrase_push::start()
     {
         saved_suppress = actions.suppress;
     
@@ -338,6 +338,8 @@
             values.consume().get_quickbook().c_str());
     
         actions.suppress = actions.suppress || !condition;
+
+        return true;
     }
     
     void cond_phrase_push::cleanup()
@@ -1733,11 +1735,13 @@
         return (*this)(actions.out);
     }
 
-    void scoped_output_push::start()
+    bool scoped_output_push::start()
     {
         actions.out.push();
         actions.phrase.push();
         actions.anchors.swap(saved_anchors);
+
+        return true;
     }
     
     void scoped_output_push::cleanup()
@@ -1747,14 +1751,29 @@
         actions.anchors.swap(saved_anchors);
     }
 
-    void set_no_eols_scoped::start()
+    bool set_no_eols_scoped::start()
     {
         saved_no_eols = actions.no_eols;
         actions.no_eols = false;
+
+        return true;
     }
 
     void set_no_eols_scoped::cleanup()
     {
         actions.no_eols = saved_no_eols;
     }
+
+    bool scoped_context_impl::start(int new_context)
+    {
+        saved_context_ = actions_.context;
+        actions_.context = new_context;
+
+        return true;
+    }
+
+    void scoped_context_impl::cleanup()
+    {
+        actions_.context = saved_context_;
+    }
 }
Modified: trunk/tools/quickbook/src/actions.hpp
==============================================================================
--- trunk/tools/quickbook/src/actions.hpp	(original)
+++ trunk/tools/quickbook/src/actions.hpp	2011-03-19 11:19:09 EDT (Sat, 19 Mar 2011)
@@ -170,7 +170,7 @@
         cond_phrase_push(quickbook::actions& x)
             : actions(x) {}
 
-        void start();
+        bool start();
         void cleanup();
 
         quickbook::actions& actions;
@@ -451,7 +451,7 @@
         scoped_output_push(quickbook::actions& actions)
             : actions(actions) {}
 
-        void start();
+        bool start();
         void cleanup();
 
         quickbook::actions& actions;
@@ -463,12 +463,25 @@
         set_no_eols_scoped(quickbook::actions& actions)
             : actions(actions) {}
 
-        void start();
+        bool start();
         void cleanup();
 
         quickbook::actions& actions;
         bool saved_no_eols;
     };
+    
+    struct scoped_context_impl : scoped_action_base
+    {
+        scoped_context_impl(quickbook::actions& actions)
+            : actions_(actions) {}
+
+        bool start(int);
+        void cleanup();
+
+    private:
+        quickbook::actions& actions_;
+        int saved_context_;
+    };
 }
 
 #ifdef BOOST_MSVC
Modified: trunk/tools/quickbook/src/actions_class.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions_class.cpp	(original)
+++ trunk/tools/quickbook/src/actions_class.cpp	2011-03-19 11:19:09 EDT (Sat, 19 Mar 2011)
@@ -42,6 +42,7 @@
         , scoped_cond_phrase(*this)
         , scoped_output(*this)
         , scoped_no_eols(*this)
+        , scoped_context(*this)
 
     // state
         , filename(fs::absolute(filein_))
Modified: trunk/tools/quickbook/src/actions_class.hpp
==============================================================================
--- trunk/tools/quickbook/src/actions_class.hpp	(original)
+++ trunk/tools/quickbook/src/actions_class.hpp	2011-03-19 11:19:09 EDT (Sat, 19 Mar 2011)
@@ -60,6 +60,8 @@
                                 scoped_output;
         scoped_parser<set_no_eols_scoped>
                                 scoped_no_eols;
+        scoped_parser<scoped_context_impl>
+                                scoped_context;
 
     // state
         fs::path                filename;
@@ -95,6 +97,7 @@
         bool                    no_eols;
         bool                    suppress;
         bool                    warned_about_breaks;
+        int                     context;
 
     // push/pop the states and the streams
         void copy_macros_for_write();
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-03-19 11:19:09 EDT (Sat, 19 Mar 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: trunk/tools/quickbook/src/grammar_impl.hpp
==============================================================================
--- trunk/tools/quickbook/src/grammar_impl.hpp	(original)
+++ trunk/tools/quickbook/src/grammar_impl.hpp	2011-03-19 11:19:09 EDT (Sat, 19 Mar 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: trunk/tools/quickbook/src/main_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/main_grammar.cpp	(original)
+++ trunk/tools/quickbook/src/main_grammar.cpp	2011-03-19 11:19:09 EDT (Sat, 19 Mar 2011)
@@ -14,10 +14,9 @@
 #include "template_tags.hpp"
 #include "block_tags.hpp"
 #include "parsers.hpp"
+#include "scoped.hpp"
 #include <boost/spirit/include/classic_core.hpp>
-#include <boost/spirit/include/classic_confix.hpp>
 #include <boost/spirit/include/classic_chset.hpp>
-#include <boost/spirit/include/classic_clear_actor.hpp>
 #include <boost/spirit/include/classic_if.hpp>
 #include <boost/spirit/include/classic_loops.hpp>
 #include <boost/spirit/include/phoenix1_primitives.hpp>
@@ -82,24 +81,66 @@
             main_grammar_local& l;
         };
 
-        struct check_element_type {
-            check_element_type(main_grammar_local const& l, element_info::context t)
-                : l(l), t(t) {}
+        struct process_element_impl : scoped_action_base {
+            process_element_impl(main_grammar_local& l)
+                : l(l) {}
+
+            bool start()
+            {
+                if (!(l.element_type & l.actions_.context))
+                    return false;
+
+                // Save the element type because it might
+                // be overridden by nested markup.
+                element_type_ = l.element_type;
+
+                if (!(element_type_ & element_info::in_phrase))
+                    l.actions_.paragraph();
+
+                l.actions_.values.reset()();
+                
+                return true;
+            }
+            
+            template <typename ResultT, typename ScannerT>
+            bool result(ResultT result, ScannerT const& scan)
+            {
+                if (result || l.element_type & element_info::in_phrase)
+                    return result;
 
-            bool operator()() const {
-                return l.element_type & t;
+                l.actions_.error(scan.first, scan.first);
+                return true;
             }
 
-            main_grammar_local const& l;
-            element_info::context t;
+            void success() { 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,
-                        block_element,
                         code, code_line, blank_line, hr,
-                        list, ordered_list, list_item,
-                        phrase_element, extended_phrase_element, element,
+                        list, list_item, element,
                         simple_phrase_end,
                         escape,
                         inline_code, simple_format,
@@ -111,6 +152,7 @@
                         template_inner_arg_1_4, brackets_1_4,
                         template_args_1_5, template_arg_1_5, template_arg_1_5_content,
                         template_inner_arg_1_5, brackets_1_5,
+                        break_,
                         command_line_macro_identifier, command_line_phrase,
                         dummy_block
                         ;
@@ -118,21 +160,25 @@
         element_info::type_enum element_type;
         cl::rule<scanner> element_rule;
         value::tag_type element_tag;
+
+        quickbook::actions& actions_;
         assign_element_type assign_element;
+        scoped_parser<process_element_impl> process_element;
+        is_block_type is_block;
 
-        main_grammar_local()
-            : assign_element(*this) {}
-        
-        check_element_type check_element(element_info::context t) const {
-            return check_element_type(*this, t);
-        }
+        main_grammar_local(quickbook::actions& actions)
+            : actions_(actions)
+            , assign_element(*this)
+            , process_element(*this)
+            , is_block(*this)
+            {}
     };
 
     void quickbook_grammar::impl::init_main()
     {
         using detail::var;
 
-        main_grammar_local& local = store_.create();
+        main_grammar_local& local = store_.add(new main_grammar_local(actions));
 
         block_skip_initial_spaces =
             *(cl::blank_p | comment) >> block_start
@@ -142,15 +188,20 @@
             local.top_level >> blank
             ;
 
-        local.top_level
-            =   local.blocks
-            >>  *(
-                    local.block_element >> !(+eol >> local.blocks)
+        local.top_level =
+            actions.scoped_context(element_info::in_block)
+            [   local.blocks
+            >>  *(  local.element
+                >>  cl::if_p(local.is_block)
+                    [   !(+eol >> local.blocks)
+                    ]
                 |   local.paragraph_separator >> local.blocks
                 |   common
                 |   cl::space_p                 [actions.space_char]
                 |   cl::anychar_p               [actions.plain_char]
-                );
+                )
+            ]
+            ;
 
         local.blocks =
            *(   local.code
@@ -172,20 +223,20 @@
             >> +eol
             ;
 
-        local.block_element
-            =   '[' >> space
-            >>  local.element
-            >>  cl::eps_p(local.check_element(element_info::in_block))
-                                                [actions.paragraph]
-                                                [actions.values.reset()]
-            >>  (   actions.values.list(detail::var(local.element_tag))
+        local.element
+            =   '['
+            >>  (   cl::eps_p(cl::punct_p)
+                >>  elements                    [local.assign_element]
+                |   elements                    [local.assign_element]
+                >>  (cl::eps_p - (cl::alnum_p | '_'))
+                )
+            >>  local.process_element()
+                [   actions.values.list(detail::var(local.element_tag))
                     [   local.element_rule
-                    >>  (   (space >> ']')
-                        |   cl::eps_p           [actions.error]
-                        )
+                    >>  space
+                    >>  ']'
                     ]                           [actions.element]
-                |   cl::eps_p                   [actions.error]
-                )
+                ]
             ;
 
         local.code =
@@ -219,6 +270,8 @@
             ;
 
         local.list_item =
+            actions.scoped_context(element_info::in_phrase)
+            [
             actions.values.save()
             [
                 *(  common
@@ -229,12 +282,15 @@
                     )                       [actions.plain_char]
                 )
             ]
+            ]
             >> +eol
             ;
 
         common =
                 local.macro
-            |   local.phrase_element
+            |   local.element
+            |   local.template_
+            |   local.break_
             |   local.code_block
             |   local.inline_code
             |   local.simple_format
@@ -250,7 +306,8 @@
             ;
 
         local.template_ =
-                cl::eps_p                       [actions.values.reset()]
+            (   '['
+            >>  space                           [actions.values.reset()]
             >>  !cl::str_p("`")                 [actions.values.entry(ph::arg1, ph::arg2, template_tags::escape)]
             >>
             ( (
@@ -265,8 +322,8 @@
                 >> space
                 >> !local.template_args
             ) )
-            >> cl::eps_p(']')
-            >> cl::eps_p                        [actions.do_template]
+            >> ']'
+            )                                   [actions.do_template]
             ;
 
         local.template_args =
@@ -315,6 +372,15 @@
             '[' >> local.template_inner_arg_1_5 >> ']'
             ;
 
+        local.break_
+            =   (   '['
+                >>  space
+                >>  "br"
+                >>  space
+                >>  ']'
+                )                               [actions.break_]
+                ;
+
         local.inline_code =
             '`' >>
             (
@@ -365,22 +431,33 @@
         simple_markup(local.simple_teletype,
             '=', actions.simple_teletype, local.simple_phrase_end);
 
-        phrase = actions.values.save()[
-           *(   common
-            |   (cl::anychar_p - phrase_end)    [actions.plain_char]
-            )
+        phrase =
+            actions.scoped_context(element_info::in_phrase)
+            [
+            actions.values.save()
+            [   *(  common
+                |   (cl::anychar_p - phrase_end)
+                                                [actions.plain_char]
+                )
+            ]
             ]
             ;
 
-        extended_phrase = actions.values.save()[
-           *(   local.extended_phrase_element
-            |   common
-            |   (cl::anychar_p - phrase_end)    [actions.plain_char]
-            )
+        extended_phrase =
+            actions.scoped_context(element_info::in_conditional)
+            [
+            actions.values.save()
+            [  *(   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
@@ -388,45 +465,7 @@
                                                 [actions.plain_char]
                 )
             ]                                   [actions.paragraph]
-            ;
-
-        local.phrase_element
-            =   '['
-            >>  space
-            >>  (   local.element
-                >>  cl::eps_p(local.check_element(element_info::in_phrase))
-                                                [actions.values.reset()]
-                >>  actions.values.list(detail::var(local.element_tag))
-                    [   local.element_rule
-                    >>  cl::eps_p(space >> ']')
-                    ]                           [actions.element]
-                |   local.template_
-                |   cl::str_p("br")             [actions.break_]
-                )
-            >>  ']'
-            ;
-
-        local.extended_phrase_element
-            =   '[' >> space
-            >>  local.element
-            >>  cl::eps_p(local.check_element(element_info::in_conditional))
-                                                [actions.paragraph]
-                                                [actions.values.reset()]
-            >>  (   actions.values.list(detail::var(local.element_tag))
-                    [   local.element_rule
-                    >>  (   (space >> ']')          
-                        |   cl::eps_p           [actions.error]
-                        )
-                    ]                           [actions.element]
-                    |   cl::eps_p               [actions.error]
-                )
-            ;
-
-        local.element
-            =   cl::eps_p(cl::punct_p)
-            >>  elements                        [local.assign_element]
-            |   elements                        [local.assign_element]
-            >>  (cl::eps_p - (cl::alnum_p | '_'))
+            ]
             ;
 
         local.escape =
@@ -448,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]
             )
             ]
+            ]
             ;
 
         //
@@ -480,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: trunk/tools/quickbook/src/parsers.hpp
==============================================================================
--- trunk/tools/quickbook/src/parsers.hpp	(original)
+++ trunk/tools/quickbook/src/parsers.hpp	2011-03-19 11:19:09 EDT (Sat, 19 Mar 2011)
@@ -65,24 +65,24 @@
             typedef phoenix::tuple_index<0> t0;
             typedef phoenix::tuple_index<1> t1;
             
-            void start(phoenix::tuple<> const&)
+            bool start(phoenix::tuple<> const&)
             {
-                impl_.start();
-                in_progress_ = true;
+                in_progress_ = impl_.start();
+                return in_progress_;
             }
             
             template <typename Arg1>
-            void start(phoenix::tuple<Arg1> const& x)
+            bool start(phoenix::tuple<Arg1> const& x)
             {
-                impl_.start(x[t0()]);
-                in_progress_ = true;
+                in_progress_ = impl_.start(x[t0()]);
+                return in_progress_;
             }
 
             template <typename Arg1, typename Arg2>
-            void start(phoenix::tuple<Arg1, Arg2> const& x)
+            bool start(phoenix::tuple<Arg1, Arg2> const& x)
             {
-                impl_.start(x[t0()], x[t1()]);
-                in_progress_ = true;
+                in_progress_ = impl_.start(x[t0()], x[t1()]);
+                return in_progress_;
             }
             
             void success()
@@ -114,16 +114,22 @@
             iterator_t save = scan.first;
 
             scoped scope(impl_);
-            scope.start(arguments_);
+            if (!scope.start(arguments_))
+                return scan.no_match();
 
             typename cl::parser_result<ParserT, ScannerT>::type result
                 = this->subject().parse(scan);
 
-            //result = scope.match(result);
+            bool success = scope.impl_.result(result, scan);
 
-            if (result) {
+            if (success) {
                 scope.success();
-                return scan.create_match(result.length(), cl::nil_t(), save, scan.first);
+                if (result) {
+                    return scan.create_match(result.length(), cl::nil_t(), save, scan.first);
+                }
+                else {
+                    return scan.create_match(scan.first.base() - save.base(), cl::nil_t(), save, scan.first);
+                }
             }
             else {
                 scope.failure();
Modified: trunk/tools/quickbook/src/rule_store.hpp
==============================================================================
--- trunk/tools/quickbook/src/rule_store.hpp	(original)
+++ trunk/tools/quickbook/src/rule_store.hpp	2011-03-19 11:19:09 EDT (Sat, 19 Mar 2011)
@@ -72,6 +72,16 @@
             instantiate i(*this);
             return i;
         }
+        
+        template <typename T>
+        T& add(T* new_)
+        {
+            std::auto_ptr<T> obj(new_);
+            store_.push_back(detail::scoped_void());
+            store_.back().store(obj.release(), &detail::delete_impl<T>);
+
+            return *new_;
+        }
 
         std::deque<detail::scoped_void> store_;
     private:
Modified: trunk/tools/quickbook/src/scoped.hpp
==============================================================================
--- trunk/tools/quickbook/src/scoped.hpp	(original)
+++ trunk/tools/quickbook/src/scoped.hpp	2011-03-19 11:19:09 EDT (Sat, 19 Mar 2011)
@@ -15,10 +15,16 @@
 
     struct scoped_action_base
     {
-        void start() {}
+        bool start() { return true; }
         void success() {}
         void failure() {}
         void cleanup() {}
+        
+        template <typename ResultT, typename ScannerT>
+        bool result(ResultT result, ScannerT const&)
+        {
+            return result;
+        }
     };
 }
 
Modified: trunk/tools/quickbook/src/syntax_highlight.hpp
==============================================================================
--- trunk/tools/quickbook/src/syntax_highlight.hpp	(original)
+++ trunk/tools/quickbook/src/syntax_highlight.hpp	2011-03-19 11:19:09 EDT (Sat, 19 Mar 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: trunk/tools/quickbook/src/values_parse.hpp
==============================================================================
--- trunk/tools/quickbook/src/values_parse.hpp	(original)
+++ trunk/tools/quickbook/src/values_parse.hpp	2011-03-19 11:19:09 EDT (Sat, 19 Mar 2011)
@@ -11,6 +11,7 @@
 
 #include "values.hpp"
 #include "parsers.hpp"
+#include "scoped.hpp"
 #include <boost/spirit/include/phoenix1_functions.hpp>
 
 #include <iostream>
@@ -18,28 +19,33 @@
 namespace quickbook {
     namespace ph = phoenix;
 
-    struct value_builder_save
+    struct value_builder_save : scoped_action_base
     {
         value_builder_save(value_builder& builder) : builder(builder) {}
 
-        void start() { builder.save(); }
-        void success() {}
-        void failure() {}
+        bool start()
+        {
+            builder.save();
+            return true;
+        }
+
         void cleanup() { builder.restore(); }
 
         value_builder& builder;
     };
 
-    struct value_builder_list
+    struct value_builder_list : scoped_action_base
     {
         value_builder_list(value_builder& builder) : builder(builder) {}
 
-        void start(value::tag_type tag = value::default_tag)
-        { builder.start_list(tag); }
+        bool start(value::tag_type tag = value::default_tag)
+        {
+            builder.start_list(tag);
+            return true;
+        }
 
         void success() { builder.finish_list(); }
         void failure() { builder.clear_list(); }
-        void cleanup() {}
 
         value_builder& builder;
     };
Modified: trunk/tools/quickbook/test/table_1_5.gold
==============================================================================
--- trunk/tools/quickbook/test/table_1_5.gold	(original)
+++ trunk/tools/quickbook/test/table_1_5.gold	2011-03-19 11:19:09 EDT (Sat, 19 Mar 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: trunk/tools/quickbook/test/table_1_5.quickbook
==============================================================================
--- trunk/tools/quickbook/test/table_1_5.quickbook	(original)
+++ trunk/tools/quickbook/test/table_1_5.quickbook	2011-03-19 11:19:09 EDT (Sat, 19 Mar 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