Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69172 - branches/quickbook-filenames/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-02-22 15:33:38


Author: danieljames
Date: 2011-02-22 15:33:24 EST (Tue, 22 Feb 2011)
New Revision: 69172
URL: http://svn.boost.org/trac/boost/changeset/69172

Log:
Use values for some more block markup.
Text files modified:
   branches/quickbook-filenames/tools/quickbook/src/actions.cpp | 50 ++++++++++++++++++++++++--------
   branches/quickbook-filenames/tools/quickbook/src/actions.hpp | 36 -----------------------
   branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp | 11 -------
   branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp | 8 ----
   branches/quickbook-filenames/tools/quickbook/src/block_element_grammar.cpp | 61 +++++++++++----------------------------
   branches/quickbook-filenames/tools/quickbook/src/block_tags.hpp | 3 +
   branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp | 12 ++++---
   branches/quickbook-filenames/tools/quickbook/src/markups.cpp | 27 +++++++++++++++++
   branches/quickbook-filenames/tools/quickbook/src/markups.hpp | 14 +++++++++
   branches/quickbook-filenames/tools/quickbook/src/quickbook.cpp | 3 +
   branches/quickbook-filenames/tools/quickbook/src/quickbook.hpp | 8 +++++
   11 files changed, 116 insertions(+), 117 deletions(-)

Modified: branches/quickbook-filenames/tools/quickbook/src/actions.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions.cpp 2011-02-22 15:33:24 EST (Tue, 22 Feb 2011)
@@ -52,6 +52,9 @@
     void header_action(quickbook::actions&, value);
     void begin_section_action(quickbook::actions&, value);
     void end_section_action(quickbook::actions&, value, file_position);
+ void block_action(quickbook::actions&, value);
+ void macro_definition_action(quickbook::actions&, value);
+ void template_body_action(quickbook::actions&, value);
 
     void element_action::operator()(iterator first, iterator) const
     {
@@ -74,6 +77,19 @@
             return begin_section_action(actions, v);
         case block_tags::end_section:
             return end_section_action(actions, v, first.get_position());
+ case block_tags::blurb:
+ case block_tags::preformatted:
+ case block_tags::blockquote:
+ case block_tags::warning:
+ case block_tags::caution:
+ case block_tags::important:
+ case block_tags::note:
+ case block_tags::tip:
+ return block_action(actions,v);
+ case block_tags::macro_definition:
+ return macro_definition_action(actions,v);
+ case block_tags::template_definition:
+ return template_body_action(actions,v);
         default:
             break;
         }
@@ -136,6 +152,16 @@
         out << pre << values.consume().get_boostbook() << post;
     }
 
+ void block_action(quickbook::actions& actions, value block)
+ {
+ if(!actions.output_pre(actions.out)) return;
+ detail::markup markup = detail::markups[block.get_tag()];
+
+ value_consumer values = block;
+ actions.out << markup.pre << values.consume().get_boostbook() << markup.post;
+ assert(!values.is());
+ }
+
     void phrase_action::operator()() const
     {
         if(!actions.output_pre(phrase)) return;
@@ -709,29 +735,27 @@
         phrase << "</inlinemediaobject>";
     }
 
- void macro_identifier_action::operator()(iterator first, iterator last) const
+ void macro_definition_action(quickbook::actions& actions, quickbook::value macro_definition)
     {
         if(actions.suppress) return;
- actions.macro_id.assign(first, last);
- actions.phrase.push(); // save the phrase
- }
 
- void macro_definition_action::operator()(iterator first, iterator last) const
- {
- if(actions.suppress) return;
+ value_consumer values = macro_definition;
+ std::string macro_id = values.consume().get_quickbook();
+ std::string phrase = values.consume().get_boostbook();
+ assert(!values.is());
+
         actions.copy_macros_for_write();
         actions.macro.add(
- actions.macro_id.begin()
- , actions.macro_id.end()
- , actions.phrase.str());
- actions.phrase.pop(); // restore the phrase
+ macro_id.begin()
+ , macro_id.end()
+ , phrase);
     }
 
- void template_body_action::operator()(iterator, iterator) const
+ void template_body_action(quickbook::actions& actions, quickbook::value template_definition)
     {
         if(actions.suppress) return;
 
- value_consumer values = actions.values.get();
+ value_consumer values = template_definition;
         std::string identifier = values.consume().get_quickbook();
 
         std::vector<std::string> template_values;

Modified: branches/quickbook-filenames/tools/quickbook/src/actions.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions.hpp 2011-02-22 15:33:24 EST (Tue, 22 Feb 2011)
@@ -520,42 +520,6 @@
         quickbook::actions& actions;
     };
 
- struct macro_identifier_action
- {
- // Handles macro identifiers
-
- macro_identifier_action(quickbook::actions& actions)
- : actions(actions) {}
-
- void operator()(iterator first, iterator last) const;
-
- quickbook::actions& actions;
- };
-
- struct macro_definition_action
- {
- // Handles macro definitions
-
- macro_definition_action(quickbook::actions& actions)
- : actions(actions) {}
-
- void operator()(iterator first, iterator last) const;
-
- quickbook::actions& actions;
- };
-
- struct template_body_action
- {
- // Handles template definitions
-
- template_body_action(quickbook::actions& actions)
- : actions(actions) {}
-
- void operator()(iterator first, iterator last) const;
-
- quickbook::actions& actions;
- };
-
     struct do_template_action
     {
         // Handles template substitutions

Modified: branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp 2011-02-22 15:33:24 EST (Tue, 22 Feb 2011)
@@ -74,15 +74,7 @@
         , inline_code(phrase, *this)
         , inside_paragraph(out, phrase, paragraph_pre, paragraph_post, *this)
         , hr(out, hr_, *this)
- , blurb(out, blurb_pre, blurb_post, *this)
- , blockquote(out, blockquote_pre, blockquote_post, *this)
         , set_no_eols(*this)
- , preformatted(out, phrase, preformatted_pre, preformatted_post, *this)
- , warning(out, warning_pre, warning_post, *this)
- , caution(out, caution_pre, caution_post, *this)
- , important(out, important_pre, important_post, *this)
- , note(out, note_pre, note_post, *this)
- , tip(out, tip_pre, tip_post, *this)
         , space_char(phrase)
         , plain_char(phrase, *this)
         , raw_char(phrase, *this)
@@ -129,10 +121,7 @@
         , variablelist(*this)
 
         , break_(phrase, *this)
- , macro_identifier(*this)
- , macro_definition(*this)
         , do_macro(phrase, *this)
- , template_body(*this)
         , do_template(*this)
         , url_pre(phrase, url_pre_, *this)
         , url_post(phrase, url_post_, *this)

Modified: branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp 2011-02-22 15:33:24 EST (Tue, 22 Feb 2011)
@@ -106,7 +106,7 @@
 
         element_action element;
         error_action error;
-
+
         scoped_parser<scoped_block_push>
                                 scoped_block;
         scoped_parser<scoped_phrase_push>
@@ -117,11 +117,8 @@
         inline_code_action inline_code;
         implicit_paragraph_action inside_paragraph;
         markup_action hr;
- tagged_action blurb, blockquote;
         scoped_parser<set_no_eols_scoped>
                                 set_no_eols;
- phrase_action preformatted;
- tagged_action warning, caution, important, note, tip;
         space space_char;
         plain_char_action plain_char;
         raw_char_action raw_char;
@@ -169,10 +166,7 @@
         variablelist_action variablelist;
 
         break_action break_;
- macro_identifier_action macro_identifier;
- macro_definition_action macro_definition;
         do_macro_action do_macro;
- template_body_action template_body;
         do_template_action do_template;
         link_action url_pre;
         markup_action url_post;

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 15:33:24 EST (Tue, 22 Feb 2011)
@@ -26,9 +26,7 @@
     struct block_element_grammar_local
     {
         cl::rule<scanner>
- heading,
- blurb, blockquote,
- warning, caution, important, note, tip,
+ heading, blockquote,
                         inner_phrase, def_macro,
                         table, table_row, variablelist,
                         varlistentry, varlistterm, varlistitem, table_cell,
@@ -99,66 +97,42 @@
             ("h6", element_info(element_info::block, &local.heading, block_tags::heading6))
             ;
 
- elements.add("blurb", element_info(element_info::block, &local.blurb));
-
- local.blurb =
- inside_paragraph [actions.blurb]
- ;
+ elements.add("blurb", element_info(element_info::block, &inside_paragraph, block_tags::blurb));
 
         elements.add
- (":", element_info(element_info::block, &local.blockquote))
+ (":", element_info(element_info::block, &local.blockquote, block_tags::blockquote));
             ;
 
         local.blockquote =
- blank >> inside_paragraph [actions.blockquote]
+ blank >> inside_paragraph
             ;
 
         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 =
- inside_paragraph [actions.warning]
- ;
-
- local.caution =
- inside_paragraph [actions.caution]
- ;
-
- local.important =
- inside_paragraph [actions.important]
- ;
-
- local.note =
- inside_paragraph [actions.note]
- ;
-
- local.tip =
- inside_paragraph [actions.tip]
+ ("warning", element_info(element_info::block, &inside_paragraph, block_tags::warning))
+ ("caution", element_info(element_info::block, &inside_paragraph, block_tags::caution))
+ ("important", element_info(element_info::block, &inside_paragraph, block_tags::important))
+ ("note", element_info(element_info::block, &inside_paragraph, block_tags::note))
+ ("tip", element_info(element_info::block, &inside_paragraph, block_tags::tip))
             ;
 
         elements.add
- ("pre", element_info(element_info::block, &local.preformatted))
+ ("pre", element_info(element_info::block, &local.preformatted, block_tags::preformatted))
             ;
 
         local.preformatted =
                 space
>> !eol
- >> actions.set_no_eols[phrase] [actions.preformatted]
+ >> actions.set_no_eols[phrase] [actions.phrase_value]
             ;
 
         elements.add
- ("def", element_info(element_info::block, &local.def_macro))
+ ("def", element_info(element_info::block, &local.def_macro, block_tags::macro_definition))
             ;
 
         local.def_macro =
                space
- >> macro_identifier [actions.macro_identifier]
- >> blank >> phrase [actions.macro_definition]
+ >> macro_identifier [actions.values.entry(ph::arg1, ph::arg2)]
+ >> blank >> phrase [actions.phrase_value]
             ;
 
         local.identifier =
@@ -170,13 +144,12 @@
             ;
 
         elements.add
- ("template", element_info(element_info::block, &local.template_))
+ ("template", element_info(element_info::block, &local.template_, block_tags::template_definition))
             ;
 
         local.template_ =
                space
- >> local.template_id [actions.values.reset()]
- [actions.values.entry(ph::arg1, ph::arg2)]
+ >> local.template_id [actions.values.entry(ph::arg1, ph::arg2)]
>> actions.values.list()[
             !(
                 space >> '['
@@ -190,7 +163,7 @@
>> ( cl::eps_p(*cl::blank_p >> cl::eol_p)
>> local.template_body [actions.values.entry(ph::arg1, ph::arg2, template_tags::block)]
                 | local.template_body [actions.values.entry(ph::arg1, ph::arg2, template_tags::phrase)]
- ) [actions.template_body]
+ )
             ;
 
         local.template_body =

Modified: branches/quickbook-filenames/tools/quickbook/src/block_tags.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/block_tags.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/block_tags.hpp 2011-02-22 15:33:24 EST (Tue, 22 Feb 2011)
@@ -17,6 +17,9 @@
         (begin_section)(end_section)
         (generic_heading)
         (heading1)(heading2)(heading3)(heading4)(heading5)(heading6)
+ (blurb)(blockquote)(preformatted)
+ (warning)(caution)(important)(note)(tip)
+ (macro_definition)(template_definition)
     )
 
     QUICKBOOK_VALUE_TAGS(table_tags, 0x250,

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 15:33:24 EST (Tue, 22 Feb 2011)
@@ -12,6 +12,7 @@
 #include "actions_class.hpp"
 #include "utils.hpp"
 #include "template_tags.hpp"
+#include "block_tags.hpp"
 #include "parsers.hpp"
 #include <boost/spirit/include/classic_core.hpp>
 #include <boost/spirit/include/classic_confix.hpp>
@@ -453,17 +454,18 @@
         //
 
         command_line =
- *cl::space_p
+ actions.values.list(block_tags::macro_definition)
+ [ *cl::space_p
>> local.command_line_macro_identifier
- [actions.macro_identifier]
+ [actions.values.entry(ph::arg1, ph::arg2)]
>> *cl::space_p
>> ( '='
>> *cl::space_p
>> local.command_line_phrase
- [actions.macro_definition]
>> *cl::space_p
- )
- | cl::eps_p [actions.macro_definition]
+ | cl::eps_p
+ ) [actions.phrase_value]
+ ] [actions.element]
             ;
 
         local.command_line_macro_identifier =

Modified: branches/quickbook-filenames/tools/quickbook/src/markups.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/markups.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/markups.cpp 2011-02-22 15:33:24 EST (Tue, 22 Feb 2011)
@@ -8,7 +8,10 @@
     http://www.boost.org/LICENSE_1_0.txt)
 =============================================================================*/
 
+#include "quickbook.hpp"
 #include "markups.hpp"
+#include "block_tags.hpp"
+#include <boost/foreach.hpp>
 
 namespace quickbook
 {
@@ -86,4 +89,28 @@
     const char* escape_post_ = "<!--quickbook-escape-postfix-->";
     const char* replaceable_pre_ = "<replaceable>";
     const char* replaceable_post_ = "</replaceable>";
+
+ namespace detail
+ {
+ std::map<value::tag_type, markup> markups;
+
+ void initialise_markups()
+ {
+ markup init_markups[] = {
+ { block_tags::blurb, blurb_pre, blurb_post },
+ { block_tags::blockquote, blockquote_pre, blockquote_post },
+ { block_tags::preformatted, preformatted_pre, preformatted_post },
+ { block_tags::warning, warning_pre, warning_post },
+ { block_tags::caution, caution_pre, caution_post },
+ { block_tags::important, important_pre, important_post },
+ { block_tags::note, note_pre, note_post },
+ { block_tags::tip, tip_pre, tip_post }
+ };
+
+ BOOST_FOREACH(markup m, init_markups)
+ {
+ markups[m.tag] = m;
+ }
+ }
+ }
 }

Modified: branches/quickbook-filenames/tools/quickbook/src/markups.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/markups.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/markups.hpp 2011-02-22 15:33:24 EST (Tue, 22 Feb 2011)
@@ -10,6 +10,9 @@
 #if !defined(BOOST_SPIRIT_MARKUPS_HPP)
 #define BOOST_SPIRIT_MARKUPS_HPP
 
+#include <map>
+#include "values.hpp"
+
 namespace quickbook
 {
     extern const char* comment_pre;
@@ -98,6 +101,17 @@
     extern const char* escape_post_;
     extern const char* replaceable_pre_;
     extern const char* replaceable_post_;
+
+ namespace detail
+ {
+ struct markup {
+ value::tag_type tag;
+ char const* pre;
+ char const* post;
+ };
+
+ extern std::map<value::tag_type, markup> markups;
+ }
 }
 
 #endif // BOOST_SPIRIT_MARKUPS_HPP

Modified: branches/quickbook-filenames/tools/quickbook/src/quickbook.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/quickbook.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/quickbook.cpp 2011-02-22 15:33:24 EST (Tue, 22 Feb 2011)
@@ -188,8 +188,9 @@
         // First thing, the filesystem should record the current working directory.
         fs::initial_path<fs::path>();
         
- // Setup out output stream.
+ // Various initialisation methods
         quickbook::detail::initialise_output();
+ quickbook::detail::initialise_markups();
 
         options_description desc("Allowed options");
 

Modified: branches/quickbook-filenames/tools/quickbook/src/quickbook.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/quickbook.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/quickbook.hpp 2011-02-22 15:33:24 EST (Tue, 22 Feb 2011)
@@ -29,6 +29,14 @@
     extern std::vector<std::string> preset_defines;
 
     int parse_file(fs::path const& filein_, actions& actor, bool ignore_docinfo = false);
+
+ // Some initialisation methods
+ //
+ // Declared here to avoid including other headers
+ namespace detail
+ {
+ void initialise_markups();
+ }
 }
 
 #endif


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