Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75269 - in branches/quickbook-dev/tools/quickbook: src test
From: dnljms_at_[hidden]
Date: 2011-11-02 04:51:43


Author: danieljames
Date: 2011-11-02 04:51:41 EDT (Wed, 02 Nov 2011)
New Revision: 75269
URL: http://svn.boost.org/trac/boost/changeset/75269

Log:
Quickbook: Deal with blocks following anchors.

Turn anchors into a special type of element that can either be a block
or a phrase, so that when immediately followed by block content, the
parser will do the right thing.

`xinclude` and conditional phrases might need similar treatment,
although they're trickier.
Text files modified:
   branches/quickbook-dev/tools/quickbook/src/grammar_impl.hpp | 11 ++++++++-
   branches/quickbook-dev/tools/quickbook/src/main_grammar.cpp | 42 ++++++++++++++++++++++++++++++++-------
   branches/quickbook-dev/tools/quickbook/src/phrase_element_grammar.cpp | 2
   branches/quickbook-dev/tools/quickbook/test/anchor-1_1.quickbook | 1
   4 files changed, 44 insertions(+), 12 deletions(-)

Modified: branches/quickbook-dev/tools/quickbook/src/grammar_impl.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/grammar_impl.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/grammar_impl.hpp 2011-11-02 04:51:41 EDT (Wed, 02 Nov 2011)
@@ -26,7 +26,13 @@
             in_block = 1,
             in_phrase = 2,
             in_conditional = 4,
- in_nested_block = 8
+ in_nested_block = 8,
+ // This is a magic value to indicate an element that
+ // might be a block or might be a phrase. It isn't
+ // perfect, if a contextual_block appears at the
+ // beginning of a paragraph it might interpreted as
+ // a block when is should be a phrase.
+ contextual_block = 16
         };
 
         enum type_enum {
@@ -34,7 +40,8 @@
             block = in_block,
             conditional_or_block = block | in_conditional,
             nested_block = conditional_or_block | in_nested_block,
- phrase = nested_block | in_phrase
+ phrase = nested_block | in_phrase,
+ maybe_block = phrase | contextual_block
         };
 
         element_info()

Modified: branches/quickbook-dev/tools/quickbook/src/main_grammar.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/main_grammar.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/main_grammar.cpp 2011-11-02 04:51:41 EDT (Wed, 02 Nov 2011)
@@ -30,6 +30,9 @@
 
     struct main_grammar_local
     {
+ ////////////////////////////////////////////////////////////////////////
+ // Local actions
+
         struct process_element_impl : scoped_action_base {
             process_element_impl(main_grammar_local& l)
                 : l(l) {}
@@ -45,6 +48,13 @@
                 if (!(info_.type & element_info::in_phrase))
                     l.actions_.paragraph();
 
+ if ((info_.type & element_info::contextual_block) &&
+ l.parse_blocks)
+ {
+ info_.type = element_info::type_enum(
+ info_.type & ~element_info::in_phrase);
+ }
+
                 l.actions_.values.builder.reset();
                 
                 return true;
@@ -93,7 +103,9 @@
             bool start(int new_context)
             {
                 saved_context_ = l_.context;
+ saved_parse_blocks_ = l_.parse_blocks;
                 l_.context = new_context;
+ l_.parse_blocks = l_.context != element_info::in_phrase;
         
                 return true;
             }
@@ -101,13 +113,18 @@
             void cleanup()
             {
                 l_.context = saved_context_;
+ l_.parse_blocks = saved_parse_blocks_;
             }
 
         private:
             main_grammar_local& l_;
             int saved_context_;
+ bool saved_parse_blocks_;
         };
 
+ ////////////////////////////////////////////////////////////////////////
+ // Local members
+
         cl::rule<scanner>
                         top_level, blocks, paragraph_separator,
                         code, code_line, blank_line, hr,
@@ -138,6 +155,7 @@
         cl::rule<scanner> simple_markup_end;
 
         int context;
+ bool parse_blocks;
         element_info info;
         element_info::type_enum element_type;
 
@@ -146,6 +164,9 @@
         scoped_parser<process_element_impl> process_element;
         is_block_type is_block;
 
+ ////////////////////////////////////////////////////////////////////////
+ // Local constructor
+
         main_grammar_local(quickbook::actions& actions)
             : actions_(actions)
             , scoped_context(*this)
@@ -154,6 +175,9 @@
             {}
     };
 
+ ////////////////////////////////////////////////////////////////////////////
+ // Local grammar
+
     void quickbook_grammar::impl::init_main()
     {
         main_grammar_local& local = cleanup_.add(
@@ -178,20 +202,22 @@
 
         local.top_level =
             local.scoped_context(element_info::in_block)
- [ local.blocks
- >> *( local.element
- >> !(cl::eps_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]
+ [ *( cl::eps_p(ph::var(local.parse_blocks)) >> local.blocks
+ | local.element [ph::var(local.parse_blocks) = false]
+ >> !(cl::eps_p(local.is_block) >> +eol)
+ [ph::var(local.parse_blocks) = true]
+ | local.paragraph_separator [ph::var(local.parse_blocks) = true]
+ | ( common
+ | cl::space_p [actions.space_char]
+ | cl::anychar_p [actions.plain_char]
+ ) [ph::var(local.parse_blocks) = false]
                 )
>> cl::eps_p [actions.paragraph]
             ]
             ;
 
         local.blocks =
- *( local.code
+ +( local.code
             | local.list
             | local.hr
             | +eol

Modified: branches/quickbook-dev/tools/quickbook/src/phrase_element_grammar.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/phrase_element_grammar.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/phrase_element_grammar.cpp 2011-11-02 04:51:41 EDT (Wed, 02 Nov 2011)
@@ -98,7 +98,7 @@
             ;
 
         elements.add
- ("#", element_info(element_info::phrase, &local.anchor, phrase_tags::anchor))
+ ("#", element_info(element_info::maybe_block, &local.anchor, phrase_tags::anchor))
             ;
 
         local.anchor =

Modified: branches/quickbook-dev/tools/quickbook/test/anchor-1_1.quickbook
==============================================================================
--- branches/quickbook-dev/tools/quickbook/test/anchor-1_1.quickbook (original)
+++ branches/quickbook-dev/tools/quickbook/test/anchor-1_1.quickbook 2011-11-02 04:51:41 EDT (Wed, 02 Nov 2011)
@@ -37,7 +37,6 @@
 [section Lists]
 
 [#a14]
-
 * Item 1
 * Item 2
 * Nested List


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