Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59290 - in branches/quickbook-1.5-spirit2: . detail
From: daniel_james_at_[hidden]
Date: 2010-01-27 16:59:47


Author: danieljames
Date: 2010-01-27 16:59:46 EST (Wed, 27 Jan 2010)
New Revision: 59290
URL: http://svn.boost.org/trac/boost/changeset/59290

Log:
'generic' link handling.
Text files modified:
   branches/quickbook-1.5-spirit2/detail/actions.cpp | 2
   branches/quickbook-1.5-spirit2/detail/actions.hpp | 40 ++++++++++++++--
   branches/quickbook-1.5-spirit2/detail/actions_class.cpp | 27 ++--------
   branches/quickbook-1.5-spirit2/detail/actions_class.hpp | 27 ++--------
   branches/quickbook-1.5-spirit2/phrase.hpp | 95 +++++++--------------------------------
   5 files changed, 66 insertions(+), 125 deletions(-)

Modified: branches/quickbook-1.5-spirit2/detail/actions.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/detail/actions.cpp (original)
+++ branches/quickbook-1.5-spirit2/detail/actions.cpp 2010-01-27 16:59:46 EST (Wed, 27 Jan 2010)
@@ -844,7 +844,7 @@
         --actions.template_depth;
     }
 
- void link_action::operator()(iterator_range x, unused_type, unused_type) const
+ void generic_link_action::operator()(char const* tag, iterator_range x) const
     {
         iterator first = x.begin(), last = x.end();
         iterator save = first;

Modified: branches/quickbook-1.5-spirit2/detail/actions.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/detail/actions.hpp (original)
+++ branches/quickbook-1.5-spirit2/detail/actions.hpp 2010-01-27 16:59:46 EST (Wed, 27 Jan 2010)
@@ -395,13 +395,42 @@
         int& error_count;
     };
 
+ struct generic_markup_action
+ {
+ template <typename Arg1> struct result { typedef void type; };
+
+ // Handles links (URL, XML refentry, function, class, member)
+
+ generic_markup_action(collector& phrase)
+ : phrase(phrase) {}
+
+ void operator()(char const* str) const
+ {
+ phrase << str;
+ }
+
+ collector& phrase;
+ };
+
     struct markup_action
     {
+ template <typename T = void> struct result { typedef void type; };
+
         // A generic markup action
 
         markup_action(collector& phrase, std::string const& str)
         : phrase(phrase), str(str) {}
 
+ void operator()() const
+ {
+ phrase << str;
+ }
+
+ void operator()(unused_type) const
+ {
+ phrase << str;
+ }
+
         void operator()(unused_type, unused_type, unused_type) const
         {
             phrase << str;
@@ -552,17 +581,18 @@
         quickbook::actions& actions;
     };
 
- struct link_action
+ struct generic_link_action
     {
+ template <typename Arg1, typename Arg2> struct result { typedef void type; };
+
         // Handles links (URL, XML refentry, function, class, member)
 
- link_action(collector& phrase, char const* tag)
- : phrase(phrase), tag(tag) {}
+ generic_link_action(collector& phrase)
+ : phrase(phrase) {}
 
- void operator()(iterator_range, unused_type, unused_type) const;
+ void operator()(char const*, iterator_range) const;
 
         collector& phrase;
- char const* tag;
     };
 
     struct variablelist_action

Modified: branches/quickbook-1.5-spirit2/detail/actions_class.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/detail/actions_class.cpp (original)
+++ branches/quickbook-1.5-spirit2/detail/actions_class.cpp 2010-01-27 16:59:46 EST (Wed, 27 Jan 2010)
@@ -99,23 +99,6 @@
         , list_format(list_buffer, list_indent, list_marks, error_count)
         , list_item(list_buffer, phrase, list_item_pre, list_item_post)
 
- , funcref_pre(phrase, funcref_pre_)
- , funcref_post(phrase, funcref_post_)
- , classref_pre(phrase, classref_pre_)
- , classref_post(phrase, classref_post_)
- , memberref_pre(phrase, memberref_pre_)
- , memberref_post(phrase, memberref_post_)
- , enumref_pre(phrase, enumref_pre_)
- , enumref_post(phrase, enumref_post_)
- , macroref_pre(phrase, macroref_pre_)
- , macroref_post(phrase, macroref_post_)
- , headerref_pre(phrase, headerref_pre_)
- , headerref_post(phrase, headerref_post_)
- , conceptref_pre(phrase, conceptref_pre_)
- , conceptref_post(phrase, conceptref_post_)
- , globalref_pre(phrase, globalref_pre_)
- , globalref_post(phrase, globalref_post_)
-
         , bold_pre(phrase, bold_pre_)
         , bold_post(phrase, bold_post_)
         , italic_pre(phrase, italic_pre_)
@@ -153,10 +136,12 @@
         , do_macro(phrase)
         , template_body(*this)
         , do_template(*this)
- , url_pre(phrase, url_pre_)
- , url_post(phrase, url_post_)
- , link_pre(phrase, link_pre_)
- , link_post(phrase, link_post_)
+ , generic_link_pre(phrase)
+ , generic_link_post(phrase)
+ , url_pre(url_pre_)
+ , url_post(url_post_)
+ , link_pre(link_pre_)
+ , link_post(link_post_)
         , table(*this)
         , start_row(phrase, table_span, table_header)
         , end_row(phrase, end_row_)

Modified: branches/quickbook-1.5-spirit2/detail/actions_class.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/detail/actions_class.hpp (original)
+++ branches/quickbook-1.5-spirit2/detail/actions_class.hpp 2010-01-27 16:59:46 EST (Wed, 27 Jan 2010)
@@ -122,23 +122,6 @@
         list_format_action list_format;
         phrase_action list_item;
 
- link_action funcref_pre;
- markup_action funcref_post;
- link_action classref_pre;
- markup_action classref_post;
- link_action memberref_pre;
- markup_action memberref_post;
- link_action enumref_pre;
- markup_action enumref_post;
- link_action macroref_pre;
- markup_action macroref_post;
- link_action headerref_pre;
- markup_action headerref_post;
- link_action conceptref_pre;
- markup_action conceptref_post;
- link_action globalref_pre;
- markup_action globalref_post;
-
         markup_action bold_pre;
         markup_action bold_post;
         markup_action italic_pre;
@@ -176,10 +159,12 @@
         do_macro_action do_macro;
         template_body_action template_body;
         do_template_action do_template;
- link_action url_pre;
- markup_action url_post;
- link_action link_pre;
- markup_action link_post;
+ generic_link_action generic_link_pre;
+ generic_markup_action generic_link_post;
+ char const* url_pre;
+ char const* url_post;
+ char const* link_pre;
+ char const* link_post;
         table_action table;
         start_row_action start_row;
         markup_action end_row;

Modified: branches/quickbook-1.5-spirit2/phrase.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/phrase.hpp (original)
+++ branches/quickbook-1.5-spirit2/phrase.hpp 2010-01-27 16:59:46 EST (Wed, 27 Jan 2010)
@@ -13,6 +13,7 @@
 #include "./grammars.hpp"
 #include "./detail/quickbook.hpp"
 #include "./detail/utils.hpp"
+#include "./detail/markups.hpp"
 #include "./parse_utils.hpp"
 #include <map>
 #include <boost/spirit/include/qi_core.hpp>
@@ -60,6 +61,7 @@
         qi::rule<Iterator, std::pair<std::string, std::string>()> image_attribute;
         
         qi::rule<Iterator, boost::iterator_range<Iterator>(char)> simple_markup;
+ qi::rule<Iterator, void(char const*, char const*, char const*)> generic_link;
     };
 
     template <typename Iterator, typename Actions>
@@ -328,19 +330,10 @@
         url =
                 '@'
>> qi::raw[*(qi::char_ -
- (']' | qi::space))] [actions.url_pre]
+ (']' | qi::space))] [ph::bind(actions.generic_link_pre, actions.url_pre, qi::_1)]
>> ( &qi::lit(']')
                 | (hard_space >> phrase)
- ) [actions.url_post]
- ;
-
- link =
- "link" >> hard_space
- >> qi::raw[*(qi::char_ -
- (']' | qi::space))] [actions.link_pre]
- >> ( &qi::lit(']')
- | (hard_space >> phrase)
- ) [actions.link_post]
+ ) [ph::bind(actions.generic_link_post, actions.url_post)]
             ;
 
         anchor =
@@ -349,77 +342,25 @@
>> qi::raw[*(qi::char_ - phrase_end)] [actions.anchor]
             ;
 
- funcref =
- "funcref" >> hard_space
- >> qi::raw[*(qi::char_ -
- (']' | hard_space))] [actions.funcref_pre]
- >> ( &qi::lit(']')
- | (hard_space >> phrase)
- ) [actions.funcref_post]
- ;
-
- classref =
- "classref" >> hard_space
- >> qi::raw[*(qi::char_ -
- (']' | hard_space))] [actions.classref_pre]
- >> ( &qi::lit(']')
- | (hard_space >> phrase)
- ) [actions.classref_post]
- ;
-
- memberref =
- "memberref" >> hard_space
- >> qi::raw[*(qi::char_ -
- (']' | hard_space))] [actions.memberref_pre]
- >> ( &qi::lit(']')
- | (hard_space >> phrase)
- ) [actions.memberref_post]
- ;
-
- enumref =
- "enumref" >> hard_space
- >> qi::raw[*(qi::char_ -
- (']' | hard_space))] [actions.enumref_pre]
- >> ( &qi::lit(']')
- | (hard_space >> phrase)
- ) [actions.enumref_post]
- ;
-
- macroref =
- "macroref" >> hard_space
- >> qi::raw[*(qi::char_ -
- (']' | hard_space))] [actions.macroref_pre]
- >> ( &qi::lit(']')
- | (hard_space >> phrase)
- ) [actions.macroref_post]
- ;
-
- headerref =
- "headerref" >> hard_space
- >> qi::raw[*(qi::char_ -
- (']' | hard_space))] [actions.headerref_pre]
- >> ( &qi::lit(']')
- | (hard_space >> phrase)
- ) [actions.headerref_post]
- ;
-
- conceptref =
- "conceptref" >> hard_space
+ generic_link =
+ qi::string(qi::_r1)
+ >> hard_space
>> qi::raw[*(qi::char_ -
- (']' | hard_space))] [actions.conceptref_pre]
+ (']' | qi::space))] [ph::bind(actions.generic_link_pre, qi::_r2, qi::_1)]
>> ( &qi::lit(']')
                 | (hard_space >> phrase)
- ) [actions.conceptref_post]
+ ) [ph::bind(actions.generic_link_post, qi::_r3)]
             ;
 
- globalref =
- "globalref" >> hard_space
- >> qi::raw[*(qi::char_ -
- (']' | hard_space))] [actions.globalref_pre]
- >> ( &qi::lit(']')
- | (hard_space >> phrase)
- ) [actions.globalref_post]
- ;
+ link = generic_link((char const*)"link", link_pre_, link_post_);
+ funcref = generic_link((char const*)"funcref", funcref_pre_, funcref_post_);
+ classref = generic_link((char const*)"classref", classref_pre_, classref_post_);
+ memberref = generic_link((char const*)"memberref", memberref_pre_, memberref_post_);
+ enumref = generic_link((char const*)"enumref", enumref_pre_, enumref_post_);
+ macroref = generic_link((char const*)"macroref", macroref_pre_, macroref_post_);
+ headerref = generic_link((char const*)"headerref", headerref_pre_, headerref_post_);
+ conceptref = generic_link((char const*)"conceptref", conceptref_pre_, conceptref_post_);
+ globalref = generic_link((char const*)"globalref", globalref_pre_, globalref_post_);
 
         bold =
                 qi::char_('*') [actions.bold_pre]


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