Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85116 - in trunk/tools/quickbook: doc src test
From: dnljms_at_[hidden]
Date: 2013-07-22 15:34:03


Author: danieljames
Date: 2013-07-22 15:34:03 EDT (Mon, 22 Jul 2013)
New Revision: 85116
URL: http://svn.boost.org/trac/boost/changeset/85116

Log:
Error if element used in incorrect context.

Should be less suprising than just not processing them. Needs more tests.

Added:
   trunk/tools/quickbook/test/link-1_7-fail.quickbook (contents, props changed)
   trunk/tools/quickbook/test/list_test-1_7-fail1.quickbook (contents, props changed)
Text files modified:
   trunk/tools/quickbook/doc/1_6.qbk | 10 +++++
   trunk/tools/quickbook/src/main_grammar.cpp | 62 +++++++++++++++++++++------------------
   trunk/tools/quickbook/test/Jamfile.v2 | 2 +
   trunk/tools/quickbook/test/link-1_7-fail.quickbook | 5 +++
   trunk/tools/quickbook/test/list_test-1_7-fail1.quickbook | 9 +++++
   5 files changed, 59 insertions(+), 29 deletions(-)

Modified: trunk/tools/quickbook/doc/1_6.qbk
==============================================================================
--- trunk/tools/quickbook/doc/1_6.qbk Mon Jul 22 15:33:38 2013 (r85115)
+++ trunk/tools/quickbook/doc/1_6.qbk 2013-07-22 15:34:03 EDT (Mon, 22 Jul 2013) (r85116)
@@ -317,6 +317,14 @@
 
 [section:1_7 Quickbook 1.7]
 
+[section:context_error Error for elements used in incorrect context]
+
+Previously if you used an element in the wrong context it would just be
+unprocessed, which was surprising. People often didn't realise that their
+element hadn't been processed. So now it's an error.
+
+[endsect]
+
 [section:source_mode Source mode for single entities]
 
 1.7 introduces a new `!` element type for setting the source mode of a single
@@ -347,7 +355,7 @@
 
 [endsect]
 
-[section:callouts Callouts in code block]
+[section:callouts Callouts in code blocks]
 
 Currently callouts can only be used in code snippets. 1.7 add
 support in normal code blocks. The same syntax is used as in

Modified: trunk/tools/quickbook/src/main_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/main_grammar.cpp Mon Jul 22 15:33:38 2013 (r85115)
+++ trunk/tools/quickbook/src/main_grammar.cpp 2013-07-22 15:34:03 EDT (Mon, 22 Jul 2013) (r85116)
@@ -157,26 +157,28 @@
 
     struct process_element_impl : scoped_action_base {
         process_element_impl(main_grammar_local& l)
- : l(l) {}
+ : l(l), element_context_error_(false) {}
 
         bool start()
         {
- if (!(l.info.type & l.context) ||
- qbk_version_n < l.info.qbk_version)
+ // This element doesn't exist in the current language version.
+ if (qbk_version_n < l.info.qbk_version)
                 return false;
 
- info_ = l.info;
-
- if (!l.list_stack.empty() && !l.list_stack.top().root &&
- info_.type == element_info::section_block)
+ // The element is not allowed in this context.
+ if (!(l.info.type & l.context))
             {
- // If in a list and the element is a section block, end the
- // list.
- list_item_action list_item(l.state_);
- list_item();
- l.clear_stack();
+ if (qbk_version_n < 107u) {
+ return false;
+ }
+ else {
+ element_context_error_ = true;
+ }
             }
- else if (info_.type != element_info::phrase &&
+
+ info_ = l.info;
+
+ if (info_.type != element_info::phrase &&
                     info_.type != element_info::maybe_block)
             {
                 paragraph_action para(l.state_);
@@ -199,12 +201,21 @@
         template <typename ResultT, typename ScannerT>
         bool result(ResultT result, ScannerT const& scan)
         {
- if (result || info_.type & element_info::in_phrase)
+ if (element_context_error_) {
+ error_message_action error(l.state_,
+ "Element not allowed in this context.");
+ error(scan.first, scan.first);
+ return true;
+ }
+ else if (result || info_.type & element_info::in_phrase) {
                 return result;
-
- error_action error(l.state_);
- error(scan.first, scan.first);
- return true;
+ }
+ else {
+ // Parse error in body.
+ error_action error(l.state_);
+ error(scan.first, scan.first);
+ return true;
+ }
         }
 
         void success(parse_iterator, parse_iterator) { l.element_type = info_.type; }
@@ -218,6 +229,7 @@
         main_grammar_local& l;
         element_info info_;
         std::string saved_source_mode_;
+ bool element_context_error_;
     };
 
     struct in_list_impl {
@@ -406,9 +418,8 @@
             ;
 
         local.paragraph =
- scoped_still_in_block(true)
- [
- scoped_context(element_info::in_top_level)
+ scoped_context(element_info::in_top_level)
+ [ scoped_still_in_block(true)
                 [ local.syntactic_block_item(element_info::is_contextual_block)
>> *( cl::eps_p(ph::var(local.still_in_block))
>> local.syntactic_block_item(element_info::is_block)
@@ -421,13 +432,8 @@
                 *cl::blank_p
>> (cl::ch_p('*') | '#')
>> (*cl::blank_p)
- >> scoped_still_in_block(true)
- [ qbk_ver(107u) >> scoped_context(element_info::in_top_level)
- [ *( cl::eps_p(ph::var(local.still_in_block))
- >> local.syntactic_block_item(element_info::is_block)
- )
- ]
- | qbk_ver(0, 107u) >> scoped_context(element_info::in_list_block)
+ >> scoped_context(element_info::in_list_block)
+ [ scoped_still_in_block(true)
                     [ *( cl::eps_p(ph::var(local.still_in_block))
>> local.syntactic_block_item(element_info::is_block)
                         )

Modified: trunk/tools/quickbook/test/Jamfile.v2
==============================================================================
--- trunk/tools/quickbook/test/Jamfile.v2 Mon Jul 22 15:33:38 2013 (r85115)
+++ trunk/tools/quickbook/test/Jamfile.v2 2013-07-22 15:34:03 EDT (Mon, 22 Jul 2013) (r85116)
@@ -68,10 +68,12 @@
     [ quickbook-test link-1_1 ]
     [ quickbook-test link-1_6 ]
     [ quickbook-test link-1_7 ]
+ [ quickbook-error-test link-1_7-fail ]
     [ quickbook-test list_test-1_5 ]
     [ quickbook-test list_test-1_6 ]
     [ quickbook-error-test list_test-1_6-fail ]
     [ quickbook-test list_test-1_7 ]
+ [ quickbook-error-test list_test-1_7-fail1 ]
     [ quickbook-test macro-1_5 ]
     [ quickbook-test macro-1_6 ]
     [ quickbook-error-test mismatched_brackets-1_1-fail ]

Added: trunk/tools/quickbook/test/link-1_7-fail.quickbook
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/tools/quickbook/test/link-1_7-fail.quickbook 2013-07-22 15:34:03 EDT (Mon, 22 Jul 2013) (r85116)
@@ -0,0 +1,5 @@
+[article Link fail test
+[quickbook 1.7]
+]
+
+[link something [table]]

Added: trunk/tools/quickbook/test/list_test-1_7-fail1.quickbook
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/tools/quickbook/test/list_test-1_7-fail1.quickbook 2013-07-22 15:34:03 EDT (Mon, 22 Jul 2013) (r85116)
@@ -0,0 +1,9 @@
+[article List Fail Test 1
+[quickbook 1.7]
+]
+
+[section List immediately following markup]
+* One
+* Two
+* Three
+[endsect]


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