Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69436 - branches/quickbook-filenames/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-03-01 04:13:58


Author: danieljames
Date: 2011-03-01 04:13:55 EST (Tue, 01 Mar 2011)
New Revision: 69436
URL: http://svn.boost.org/trac/boost/changeset/69436

Log:
More use of phoenix.
Text files modified:
   branches/quickbook-filenames/tools/quickbook/src/block_element_grammar.cpp | 2 -
   branches/quickbook-filenames/tools/quickbook/src/doc_info_grammar.cpp | 2
   branches/quickbook-filenames/tools/quickbook/src/grammar_impl.hpp | 3 ++
   branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp | 57 ++++++++++++++-------------------------
   branches/quickbook-filenames/tools/quickbook/src/parsers.hpp | 10 ++----
   branches/quickbook-filenames/tools/quickbook/src/phrase_element_grammar.cpp | 2 -
   branches/quickbook-filenames/tools/quickbook/src/utils.hpp | 19 -------------
   7 files changed, 28 insertions(+), 67 deletions(-)

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-03-01 04:13:55 EST (Tue, 01 Mar 2011)
@@ -39,8 +39,6 @@
 
     void quickbook_grammar::impl::init_block_elements()
     {
- using detail::var;
-
         block_element_grammar_local& local = store_.create();
 
         local.element_id =

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-03-01 04:13:55 EST (Tue, 01 Mar 2011)
@@ -123,7 +123,7 @@
                                             [actions.error("Unrecognized document attribute: '%s'.")]
                     )
>> hard_space
- >> actions.values.list(detail::var(local.attribute_tag))
+ >> actions.values.list(ph::var(local.attribute_tag))
                     [local.attribute_rule]
>> space
>> ']'

Modified: branches/quickbook-filenames/tools/quickbook/src/grammar_impl.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/grammar_impl.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/grammar_impl.hpp 2011-03-01 04:13:55 EST (Tue, 01 Mar 2011)
@@ -37,6 +37,9 @@
             phrase = nested_block | in_phrase
         };
 
+ element_info()
+ : type(nothing), rule(), tag(0) {}
+
         element_info(
                 type_enum t,
                 cl::rule<scanner>* r,

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-03-01 04:13:55 EST (Tue, 01 Mar 2011)
@@ -20,8 +20,8 @@
 #include <boost/spirit/include/classic_if.hpp>
 #include <boost/spirit/include/classic_loops.hpp>
 #include <boost/spirit/include/classic_attribute.hpp>
+#include <boost/spirit/include/classic_lazy.hpp>
 #include <boost/spirit/include/phoenix1_primitives.hpp>
-#include <boost/spirit/include/phoenix1_casts.hpp>
 
 namespace quickbook
 {
@@ -29,35 +29,21 @@
 
     struct main_grammar_local
     {
- struct assign_element_type {
- assign_element_type(main_grammar_local& l) : l(l) {}
-
- void operator()(element_info& t) const {
- l.element_type = t.type;
- l.element_rule = *t.rule;
- l.element_tag = t.tag;
- }
-
- main_grammar_local& l;
- };
-
         struct process_element_impl : scoped_action_base {
             process_element_impl(main_grammar_local& l)
                 : l(l) {}
 
             bool start()
             {
- if (!(l.element_type & l.actions_.context))
+ if (!(l.info.type & l.actions_.context))
                     return false;
 
- // Save the element type because it might
- // be overridden by nested markup.
- element_type_ = l.element_type;
+ info_ = l.info;
 
- if (!(element_type_ & element_info::in_phrase))
+ if (!(info_.type & element_info::in_phrase))
                     l.actions_.paragraph();
 
- l.actions_.values.reset()();
+ l.actions_.values.builder.reset();
                 
                 return true;
             }
@@ -65,18 +51,18 @@
             template <typename ResultT, typename ScannerT>
             bool result(ResultT result, ScannerT const& scan)
             {
- if (result || l.element_type & element_info::in_phrase)
+ if (result || info_.type & element_info::in_phrase)
                     return result;
 
                 l.actions_.error(scan.first, scan.first);
                 return true;
             }
 
- void success() { l.element_type = element_type_; }
+ void success() { l.element_type = info_.type; }
             void failure() { l.element_type = element_info::nothing; }
 
             main_grammar_local& l;
- element_info::type_enum element_type_;
+ element_info info_;
         };
         
         struct is_block_type
@@ -91,7 +77,7 @@
 
             bool operator()() const
             {
- return !(l_.element_type & element_info::in_phrase);
+ return l_.element_type && !(l_.element_type & element_info::in_phrase);
             }
             
             main_grammar_local& l_;
@@ -100,7 +86,7 @@
         cl::rule<scanner>
                         top_level, blocks, paragraph_separator,
                         code, code_line, blank_line, hr,
- list, list_item, element,
+ list, list_item,
                         nested_char, escape,
                         inline_code,
                         template_,
@@ -115,28 +101,26 @@
                         dummy_block
                         ;
 
+ cl::rule<scanner> element;
+
         struct simple_markup_closure
             : cl::closure<simple_markup_closure, char>
         {
             member1 mark;
         };
 
- cl::rule<scanner, simple_markup_closure::context_t>
- simple_markup;
+ cl::rule<scanner, simple_markup_closure::context_t> simple_markup;
         cl::rule<scanner> simple_markup_end;
 
+ element_info info;
         element_info::type_enum element_type;
- cl::rule<scanner> element_rule;
- value::tag_type element_tag;
 
         quickbook::actions& actions_;
- assign_element_type assign_element;
         scoped_parser<process_element_impl> process_element;
         is_block_type is_block;
 
         main_grammar_local(quickbook::actions& actions)
             : actions_(actions)
- , assign_element(*this)
             , process_element(*this)
             , is_block(*this)
             {}
@@ -144,8 +128,6 @@
 
     void quickbook_grammar::impl::init_main()
     {
- using detail::var;
-
         main_grammar_local& local = store_.add(new main_grammar_local(actions));
 
         block_skip_initial_spaces =
@@ -194,13 +176,14 @@
         local.element
             = '['
>> ( cl::eps_p(cl::punct_p)
- >> elements [local.assign_element]
- | elements [local.assign_element]
+ >> elements [ph::var(local.info) = ph::arg1]
+ | elements [ph::var(local.info) = ph::arg1]
>> (cl::eps_p - (cl::alnum_p | '_'))
                 )
>> local.process_element()
- [ actions.values.list(detail::var(local.element_tag))
- [ local.element_rule
+ [ actions.values.list(ph::var(local.info.tag))
+
+ [ cl::lazy_p(*ph::var(local.info.rule))
>> space
>> ']'
                     ] [actions.element]
@@ -563,7 +546,7 @@
 
         phrase_end =
                 ']'
- | cl::eps_p(var(actions.no_eols))
+ | cl::eps_p(ph::var(actions.no_eols))
>> cl::eol_p >> *cl::blank_p >> cl::eol_p
             ; // Make sure that we don't go
                                                 // past a single block, except

Modified: branches/quickbook-filenames/tools/quickbook/src/parsers.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/parsers.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/parsers.hpp 2011-03-01 04:13:55 EST (Tue, 01 Mar 2011)
@@ -14,7 +14,9 @@
 
 #include <boost/spirit/include/classic_core.hpp>
 #include <boost/spirit/include/classic_nil.hpp>
+#include <boost/spirit/include/phoenix1_primitives.hpp>
 #include <boost/spirit/include/phoenix1_tuples.hpp>
+#include <boost/spirit/include/phoenix1_binders.hpp>
 
 namespace quickbook {
     namespace cl = boost::spirit::classic;
@@ -53,10 +55,6 @@
 
         struct scoped
         {
- typedef void result_type;
- template <typename Arg1 = void, typename Arg2 = void>
- struct result { typedef void type; };
-
             explicit scoped(Impl const& impl)
                 : impl_(impl)
                 , in_progress_(false)
@@ -74,14 +72,14 @@
             template <typename Arg1>
             bool start(phoenix::tuple<Arg1> const& x)
             {
- in_progress_ = impl_.start(x[t0()]);
+ in_progress_ = phoenix::bind(&Impl::start)(phoenix::var(impl_), x[t0()])();
                 return in_progress_;
             }
 
             template <typename Arg1, typename Arg2>
             bool start(phoenix::tuple<Arg1, Arg2> const& x)
             {
- in_progress_ = impl_.start(x[t0()], x[t1()]);
+ in_progress_ = phoenix::bind(&Impl::start)(phoenix::var(impl_), x[t0()], x[t1()])();
                 return in_progress_;
             }
             

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-03-01 04:13:55 EST (Tue, 01 Mar 2011)
@@ -32,8 +32,6 @@
 
     void quickbook_grammar::impl::init_phrase_elements()
     {
- using detail::var;
-
         phrase_element_grammar_local& local = store_.create();
 
         elements.add

Modified: branches/quickbook-filenames/tools/quickbook/src/utils.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/utils.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/utils.hpp 2011-03-01 04:13:55 EST (Tue, 01 Mar 2011)
@@ -12,7 +12,6 @@
 
 #include <string>
 #include <cctype>
-#include <boost/ref.hpp>
 #include <boost/assert.hpp>
 #include <boost/filesystem/v3/path.hpp>
 #include <boost/range/algorithm_ext/push_back.hpp>
@@ -42,24 +41,6 @@
         return out_name;
     }
 
- template <typename T>
- struct var_wrapper
- : public ::boost::reference_wrapper<T>
- {
- typedef ::boost::reference_wrapper<T> parent;
-
- explicit inline var_wrapper(T& t) : parent(t) {}
-
- inline T& operator()() const { return parent::get(); }
- };
-
- template <typename T>
- inline var_wrapper<T>
- var(T& t)
- {
- return var_wrapper<T>(t);
- }
-
     // un-indent a code segment
     void unindent(std::string& program);
 


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