Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69168 - branches/quickbook-filenames/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-02-22 15:30:14


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

Log:
Use phoenix for some actions.
Text files modified:
   branches/quickbook-filenames/tools/quickbook/src/actions.cpp | 10 +++
   branches/quickbook-filenames/tools/quickbook/src/actions.hpp | 12 ++++
   branches/quickbook-filenames/tools/quickbook/src/block_element_grammar.cpp | 21 +++++---
   branches/quickbook-filenames/tools/quickbook/src/doc_info_grammar.cpp | 35 ++++++--------
   branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp | 25 +++++-----
   branches/quickbook-filenames/tools/quickbook/src/phrase_element_grammar.cpp | 11 ++--
   branches/quickbook-filenames/tools/quickbook/src/value_tags.hpp | 4
   branches/quickbook-filenames/tools/quickbook/src/values_parse.hpp | 93 +++++++++++++++------------------------
   8 files changed, 101 insertions(+), 110 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:30:11 EST (Tue, 22 Feb 2011)
@@ -1596,14 +1596,20 @@
         phrase.swap(out);
     }
 
- void phrase_to_docinfo_action::operator()(iterator first, iterator last) const
+ void phrase_to_docinfo_action_impl::operator()(iterator first, iterator last,
+ value::tag_type tag) const
     {
         if(!actions.output_pre(actions.phrase)) return;
 
         std::string encoded;
         actions.phrase.swap(encoded);
         actions.values.builder.insert(
- qbk_bbk_value(first, last, encoded, actions.values.builder.release_tag()));
+ qbk_bbk_value(first, last, encoded, tag));
+ }
+
+ void phrase_to_docinfo_action_impl::operator()(iterator first, iterator last) const
+ {
+ return (*this)(first, last, actions.values.builder.release_tag());
     }
     
     void phrase_to_value_action::operator()(iterator first, iterator last) const

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:30:11 EST (Tue, 22 Feb 2011)
@@ -16,12 +16,14 @@
 #include <stack>
 #include <algorithm>
 #include <boost/filesystem/v3/operations.hpp>
+#include <boost/spirit/include/phoenix1_functions.hpp>
 #include <boost/foreach.hpp>
 #include <boost/tuple/tuple.hpp>
 #include "fwd.hpp"
 #include "collector.hpp"
 #include "template_stack.hpp"
 #include "utils.hpp"
+#include "values.hpp"
 
 #ifdef BOOST_MSVC
 // disable copy/assignment could not be generated, unreferenced formal params
@@ -725,15 +727,21 @@
         quickbook::actions& actions;
     };
 
- struct phrase_to_docinfo_action
+ struct phrase_to_docinfo_action_impl
     {
- phrase_to_docinfo_action(quickbook::actions& actions)
+ template <typename Arg1, typename Arg2, typename Arg3 = void>
+ struct result { typedef void type; };
+
+ phrase_to_docinfo_action_impl(quickbook::actions& actions)
             : actions(actions) {}
 
         void operator()(iterator first, iterator last) const;
+ void operator()(iterator first, iterator last, value::tag_type) const;
 
         quickbook::actions& actions;
     };
+
+ typedef phoenix::function<phrase_to_docinfo_action_impl> phrase_to_docinfo_action;
 
     struct phrase_to_value_action
     {

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:30:11 EST (Tue, 22 Feb 2011)
@@ -16,10 +16,12 @@
 #include <boost/spirit/include/classic_assign_actor.hpp>
 #include <boost/spirit/include/classic_if.hpp>
 #include <boost/spirit/include/classic_clear_actor.hpp>
+#include <boost/spirit/include/phoenix1_primitives.hpp>
 
 namespace quickbook
 {
     namespace cl = boost::spirit::classic;
+ namespace ph = phoenix;
 
     struct block_element_grammar_local
     {
@@ -46,7 +48,7 @@
         local.element_id =
             !( ':'
>> ( cl::if_p(qbk_since(105u)) [space]
- >> (+(cl::alnum_p | '_')) [actions.values.entry(general_tags::element_id)]
+ >> (+(cl::alnum_p | '_')) [actions.values.entry(ph::arg1, ph::arg2, general_tags::element_id)]
                 | cl::eps_p [actions.element_id_warning]
                 )
             )
@@ -79,7 +81,7 @@
             ;
 
         local.end_section =
- cl::eps_p [actions.values.entry(block_tags::end_section)]
+ cl::eps_p [actions.values.entry(ph::arg1, ph::arg2, block_tags::end_section)]
                                                 [actions.end_section]
             ;
 
@@ -216,20 +218,21 @@
 
         local.template_ =
                space
- >> local.template_id [actions.values.reset][actions.values.entry]
+ >> local.template_id [actions.values.reset()]
+ [actions.values.entry(ph::arg1, ph::arg2)]
>> actions.values.scoped[
             !(
                 space >> '['
>> *(
                         space
- >> local.template_id [actions.values.entry]
+ >> local.template_id [actions.values.entry(ph::arg1, ph::arg2)]
                     )
>> space >> ']'
             )
             ]
>> ( cl::eps_p(*cl::blank_p >> cl::eol_p)
- >> local.template_body [actions.values.entry(template_tags::block)]
- | local.template_body [actions.values.entry(template_tags::phrase)]
+ >> 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]
             ;
 
@@ -245,7 +248,7 @@
 
         local.variablelist =
                 (cl::eps_p(*cl::blank_p >> cl::eol_p) | space)
- >> (*(cl::anychar_p - eol)) [actions.values.entry(table_tags::title)]
+ >> (*(cl::anychar_p - eol)) [actions.values.entry(ph::arg1, ph::arg2, table_tags::title)]
>> (+eol) [actions.output_pre]
>> *local.varlistentry
>> cl::eps_p [actions.variablelist]
@@ -297,7 +300,7 @@
                 (cl::eps_p(*cl::blank_p >> cl::eol_p) | space)
>> local.element_id_1_5
>> (cl::eps_p(*cl::blank_p >> cl::eol_p) | space)
- >> (*(cl::anychar_p - eol)) [actions.values.entry(table_tags::title)]
+ >> (*(cl::anychar_p - eol)) [actions.values.entry(ph::arg1, ph::arg2, table_tags::title)]
>> (+eol) [actions.output_pre]
>> *local.table_row
>> cl::eps_p [actions.table]
@@ -364,7 +367,7 @@
             [ cl::eps_p [actions.inner_phrase_pre]
>> phrase
>> cl::eps_p [actions.inner_phrase_post]
- ] [actions.docinfo_value]
+ ] [actions.docinfo_value(ph::arg1, ph::arg2)]
             ;
     }
 }

Modified: branches/quickbook-filenames/tools/quickbook/src/doc_info_grammar.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/doc_info_grammar.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/doc_info_grammar.cpp 2011-02-22 15:30:11 EST (Tue, 22 Feb 2011)
@@ -16,6 +16,7 @@
 #include <boost/spirit/include/classic_loops.hpp>
 #include <boost/spirit/include/classic_symbols.hpp>
 #include <boost/spirit/include/classic_chset.hpp>
+#include <boost/spirit/include/phoenix1_primitives.hpp>
 
 namespace quickbook
 {
@@ -98,12 +99,11 @@
             space
>> '[' >> space
>> (local.doc_types >> cl::eps_p)
- [actions.values.reset]
- [actions.values.entry(doc_info_tags::type)]
+ [actions.values.reset()]
+ [actions.values.entry(ph::arg1, ph::arg2, doc_info_tags::type)]
>> hard_space
>> ( *(~cl::eps_p(cl::ch_p('[') | ']' | cl::eol_p) >> local.char_)
- ) [actions.values.tag(doc_info_tags::title)]
- [actions.docinfo_value]
+ ) [actions.docinfo_value(ph::arg1, ph::arg2, doc_info_tags::title)]
>> !(
                     space >> '[' >>
                         local.quickbook_version
@@ -115,7 +115,7 @@
>> space
>> ( local.doc_attributes
                                             [local.assign_attribute]
- [actions.values.tag]
+ [actions.values.tag(ph::arg1)]
                     | (+(cl::alnum_p | '_' | '-'))
                                             [local.fallback_attribute]
                                             [actions.error("Unrecognized document attribute: '%s'.")]
@@ -126,7 +126,7 @@
>> ']'
>> +cl::eol_p
                 )
- >> space [actions.values.sort]
+ >> space [actions.values.sort()]
>> ']'
>> +cl::eol_p
             ;
@@ -145,7 +145,7 @@
 
         // TODO: Restrictions on doc_id and doc_dirname?
 
- local.doc_simple = (*(~cl::eps_p(']') >> local.char_)) [actions.docinfo_value];
+ local.doc_simple = (*(~cl::eps_p(']') >> local.char_)) [actions.docinfo_value(ph::arg1, ph::arg2)];
         local.attribute_rules[doc_info_attributes::version] = &local.doc_simple;
         local.attribute_rules[doc_info_attributes::id] = &local.doc_simple;
         local.attribute_rules[doc_info_attributes::dirname] = &local.doc_simple;
@@ -166,19 +166,17 @@
             *actions.values.scoped(doc_info_attributes::copyright)
             [
                 +( local.doc_copyright_year
- [actions.values.entry(doc_info_tags::copyright_year)]
+ [actions.values.entry(ph::arg1, ph::arg2, doc_info_tags::copyright_year)]
>> space
>> !( '-'
>> space
>> local.doc_copyright_year
- [actions.values.entry(doc_info_tags::copyright_year_end)]
+ [actions.values.entry(ph::arg1, ph::arg2, doc_info_tags::copyright_year_end)]
                     )
>> !cl::ch_p(',')
                 )
>> space
- >> local.doc_copyright_holder
- [actions.values.tag(doc_info_tags::copyright_name)]
- [actions.docinfo_value]
+ >> local.doc_copyright_holder [actions.docinfo_value(ph::arg1, ph::arg2, doc_info_tags::copyright_name)]
>> !cl::ch_p(',')
>> space
             ]
@@ -186,7 +184,7 @@
 
         local.attribute_rules[doc_info_attributes::copyright] = &local.doc_copyright;
 
- local.doc_phrase = simple_phrase[actions.docinfo_value];
+ local.doc_phrase = simple_phrase[actions.docinfo_value(ph::arg1, ph::arg2)];
         local.attribute_rules[doc_info_attributes::purpose] = &local.doc_phrase;
         local.attribute_rules[doc_info_attributes::license] = &local.doc_phrase;
 
@@ -194,12 +192,10 @@
                 '['
>> space
>> (*(~cl::eps_p(',') >> local.char_))
- [actions.values.tag(doc_info_tags::author_surname)]
- [actions.docinfo_value]
+ [actions.docinfo_value(ph::arg1, ph::arg2, doc_info_tags::author_surname)]
>> ',' >> space
>> (*(~cl::eps_p(']') >> local.char_))
- [actions.values.tag(doc_info_tags::author_first)]
- [actions.docinfo_value]
+ [actions.docinfo_value(ph::arg1, ph::arg2, doc_info_tags::author_first)]
>> ']'
             ;
 
@@ -230,11 +226,10 @@
         local.doc_biblioid =
                 actions.values.scoped(doc_info_attributes::biblioid)
                 [
- (+cl::alnum_p) [actions.values.entry(doc_info_tags::biblioid_class)]
+ (+cl::alnum_p) [actions.values.entry(ph::arg1, ph::arg2, doc_info_tags::biblioid_class)]
>> hard_space
>> (+(~cl::eps_p(']') >> local.char_))
- [actions.values.tag(doc_info_tags::biblioid_value)]
- [actions.docinfo_value]
+ [actions.docinfo_value(ph::arg1, ph::arg2, doc_info_tags::biblioid_value)]
                 ]
             ;
 

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:30:11 EST (Tue, 22 Feb 2011)
@@ -19,11 +19,12 @@
 #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>
 
 namespace quickbook
 {
     namespace cl = boost::spirit::classic;
-
+
     template <typename Rule, typename Action>
     inline void
     simple_markup(
@@ -172,7 +173,7 @@
>> local.element
>> cl::eps_p(local.check_element(element_info::in_block))
                                                 [actions.inside_paragraph]
- [actions.values.reset]
+ [actions.values.reset()]
>> ( local.element_rule
>> ( (space >> ']') [actions.element]
                     | cl::eps_p [actions.error]
@@ -236,18 +237,18 @@
             ;
 
         local.template_ =
- cl::eps_p [actions.values.reset]
- >> !cl::str_p("`") [actions.values.entry(template_tags::escape)]
+ cl::eps_p [actions.values.reset()]
+ >> !cl::str_p("`") [actions.values.entry(ph::arg1, ph::arg2, template_tags::escape)]
>>
             ( (
                 (cl::eps_p(cl::punct_p)
>> actions.templates.scope
- ) [actions.values.entry(template_tags::identifier)]
+ ) [actions.values.entry(ph::arg1, ph::arg2, template_tags::identifier)]
>> !local.template_args
             ) | (
                 (actions.templates.scope
>> cl::eps_p(hard_space)
- ) [actions.values.entry(template_tags::identifier)]
+ ) [actions.values.entry(ph::arg1, ph::arg2, template_tags::identifier)]
>> space
>> !local.template_args
             ) )
@@ -267,8 +268,8 @@
 
         local.template_arg_1_4 =
             ( cl::eps_p(*cl::blank_p >> cl::eol_p)
- >> local.template_inner_arg_1_4 [actions.values.entry(template_tags::block)]
- | local.template_inner_arg_1_4 [actions.values.entry(template_tags::phrase)]
+ >> local.template_inner_arg_1_4 [actions.values.entry(ph::arg1, ph::arg2, template_tags::block)]
+ | local.template_inner_arg_1_4 [actions.values.entry(ph::arg1, ph::arg2, template_tags::phrase)]
             )
             ;
 
@@ -284,8 +285,8 @@
 
         local.template_arg_1_5 =
             ( cl::eps_p(*cl::blank_p >> cl::eol_p)
- >> local.template_arg_1_5_content [actions.values.entry(template_tags::block)]
- | local.template_arg_1_5_content [actions.values.entry(template_tags::phrase)]
+ >> local.template_arg_1_5_content [actions.values.entry(ph::arg1, ph::arg2, template_tags::block)]
+ | local.template_arg_1_5_content [actions.values.entry(ph::arg1, ph::arg2, template_tags::phrase)]
             )
             ;
 
@@ -382,7 +383,7 @@
>> space
>> ( local.element
>> cl::eps_p(local.check_element(element_info::in_phrase))
- [actions.values.reset]
+ [actions.values.reset()]
>> local.element_rule
>> cl::eps_p(space >> ']') [actions.element]
                 | local.template_
@@ -396,7 +397,7 @@
>> local.element
>> cl::eps_p(local.check_element(element_info::in_conditional))
                                                 [actions.inside_paragraph]
- [actions.values.reset]
+ [actions.values.reset()]
>> ( local.element_rule
>> ( (space >> ']') [actions.element]
                     | cl::eps_p [actions.error]

Modified: branches/quickbook-filenames/tools/quickbook/src/phrase_element_grammar.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/phrase_element_grammar.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/phrase_element_grammar.cpp 2011-02-22 15:30:11 EST (Tue, 22 Feb 2011)
@@ -15,6 +15,7 @@
 #include <boost/spirit/include/classic_assign_actor.hpp>
 #include <boost/spirit/include/classic_clear_actor.hpp>
 #include <boost/spirit/include/classic_if.hpp>
+#include <boost/spirit/include/phoenix1_primitives.hpp>
 
 namespace quickbook
 {
@@ -46,7 +47,7 @@
 
         local.cond_phrase =
                 blank
- >> macro_identifier [actions.values.entry]
+ >> macro_identifier [actions.values.entry(ph::arg1, ph::arg2)]
>> actions.scoped_cond_phrase[extended_phrase]
             ;
 
@@ -60,21 +61,21 @@
                         (+(
                             *cl::space_p
>> +(cl::anychar_p - (cl::space_p | phrase_end | '['))
- )) [actions.values.entry]
+ )) [actions.values.entry(ph::arg1, ph::arg2)]
>> hard_space
>> *actions.values.scoped[
                             '['
>> (*(cl::alnum_p | '_'))
- [actions.values.entry]
+ [actions.values.entry(ph::arg1, ph::arg2)]
>> space
>> (*(cl::anychar_p - (phrase_end | '[')))
- [actions.values.entry]
+ [actions.values.entry(ph::arg1, ph::arg2)]
>> ']'
>> space
                         ]
                 ].else_p [
                         (*(cl::anychar_p - phrase_end))
- [actions.values.entry]
+ [actions.values.entry(ph::arg1, ph::arg2)]
                 ]
>> cl::eps_p(']') [actions.image]
             ;

Modified: branches/quickbook-filenames/tools/quickbook/src/value_tags.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/value_tags.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/value_tags.hpp 2011-02-22 15:30:11 EST (Tue, 22 Feb 2011)
@@ -18,7 +18,7 @@
 
 #define QUICKBOOK_VALUE_TAGS(tags_name, start_index, values) \
     struct tags_name { \
- enum { \
+ enum tags_name##_enum { \
             previous_index = start_index - 1, \
             BOOST_PP_SEQ_ENUM(values), \
             end_index \
@@ -43,7 +43,7 @@
 
 #define QUICKBOOK_VALUE_NAMED_TAGS(tags_name, start_index, values) \
     struct tags_name { \
- enum { \
+ enum tags_name##_enum { \
             previous_index = start_index - 1 \
             BOOST_PP_SEQ_FOR_EACH(QUICKBOOK_VALUE_NAMED_ENUM, _, values), \
             end_index \

Modified: branches/quickbook-filenames/tools/quickbook/src/values_parse.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/values_parse.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/values_parse.hpp 2011-02-22 15:30:11 EST (Tue, 22 Feb 2011)
@@ -11,9 +11,11 @@
 
 #include "values.hpp"
 #include <boost/spirit/include/classic_core.hpp>
+#include <boost/spirit/include/phoenix1_functions.hpp>
 
 namespace quickbook {
     namespace cl = boost::spirit::classic;
+ namespace ph = phoenix;
 
     struct value_builder_save
     {
@@ -158,64 +160,41 @@
         value::tag_type tag_;
     };
 
- /* value_scoped_list_gen
- */
-
- struct value_string_entry {
- value_string_entry(value_builder& b, std::string const& v, value::tag_type t = value::no_tag)
- : b(b), v(v), tag_(t) {}
-
- template <typename Iterator>
- void operator()(Iterator, Iterator) const {
- b.insert(bbk_value(v, tag_));
- }
-
- value_builder& b;
- std::string v;
- value::tag_type tag_;
- };
-
     struct value_entry
     {
- value_entry(value_builder& b, value::tag_type t = value::no_tag)
- : b(b), tag_(t) {}
-
- template <typename Iterator>
- void operator()(Iterator begin, Iterator end) const {
- b.insert(qbk_value(begin, end, tag_));
- }
-
- value_string_entry operator()(std::string const& value) {
- return value_string_entry(b, value, tag_);
- }
+ template <typename Arg1, typename Arg2 = void, typename Arg3 = void, typename Arg4 = void>
+ struct result {
+ typedef void type;
+ };
 
- value_string_entry operator()(value::tag_type tag, std::string const& value) {
- return value_string_entry(b, value, tag);
- }
+ value_entry(value_builder& b)
+ : b(b) {}
 
- value_entry operator()(value::tag_type const& value) {
- return value_entry(b, value);
+ template <typename Iterator>
+ void operator()(Iterator begin, Iterator end,
+ value::tag_type tag = value::no_tag) const
+ {
+ b.insert(qbk_value(begin, end, tag));
         }
 
- value_builder& b;
- value::tag_type tag_;
- };
-
- struct value_fixed_tag {
- value_fixed_tag(value_builder& b, value::tag_type v)
- : b(b), v(v) {}
-
         template <typename Iterator>
- void operator()(Iterator, Iterator) const {
- b.set_tag(v);
+ void operator()(Iterator begin, Iterator,
+ std::string const& v,
+ value::tag_type tag = value::no_tag) const
+ {
+ b.insert(qbk_value(v, begin.get_position(), tag));
         }
 
         value_builder& b;
- value::tag_type v;
     };
 
     struct value_tag
     {
+ template <typename Arg>
+ struct result {
+ typedef void type;
+ };
+
         value_tag(value_builder& b)
             : b(b) {}
 
@@ -223,20 +202,17 @@
             b.set_tag(value);
         }
 
- value_fixed_tag operator()(value::tag_type value) {
- return value_fixed_tag(b, value);
- }
-
         value_builder& b;
     };
 
     struct value_reset
     {
+ typedef void result_type;
+
         value_reset(value_builder& b)
             : b(b) {}
 
- template <typename Iterator>
- void operator()(Iterator, Iterator) const {
+ void operator()() const {
             b.reset();
         }
 
@@ -245,11 +221,12 @@
     
     struct value_sort
     {
+ typedef void result_type;
+
         value_sort(value_builder& b)
             : b(b) {}
 
- template <typename Iterator>
- void operator()(Iterator, Iterator) const {
+ void operator()() const {
             b.sort_list();
         }
 
@@ -261,10 +238,10 @@
         value_parser()
             : builder()
             , save(builder)
- , reset(builder)
             , scoped(builder)
- , tag(builder)
             , entry(builder)
+ , reset(builder)
+ , tag(builder)
             , sort(builder)
             {}
     
@@ -272,11 +249,11 @@
 
         value_builder builder;
         value_save_gen save;
- value_reset reset;
         value_scoped_list_gen scoped;
- value_tag tag;
- value_entry entry;
- value_sort sort;
+ ph::function<value_entry> entry;
+ ph::function<value_reset> reset;
+ ph::function<value_tag> tag;
+ ph::function<value_sort> sort;
     };
 }
 


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