|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r69173 - branches/quickbook-filenames/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-02-22 15:35:08
Author: danieljames
Date: 2011-02-22 15:35:03 EST (Tue, 22 Feb 2011)
New Revision: 69173
URL: http://svn.boost.org/trac/boost/changeset/69173
Log:
Better scoped_parser.
Added:
branches/quickbook-filenames/tools/quickbook/src/scoped.hpp (contents, props changed)
Text files modified:
branches/quickbook-filenames/tools/quickbook/src/actions.cpp | 78 ++++-------------
branches/quickbook-filenames/tools/quickbook/src/actions.hpp | 74 +++++-----------
branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp | 20 ++--
branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp | 29 ++---
branches/quickbook-filenames/tools/quickbook/src/block_element_grammar.cpp | 19 ++-
branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp | 17 ++-
branches/quickbook-filenames/tools/quickbook/src/markups.cpp | 42 ++++----
branches/quickbook-filenames/tools/quickbook/src/parsers.hpp | 166 +++++++++++++++++++++++++++++++------
branches/quickbook-filenames/tools/quickbook/src/phrase_element_grammar.cpp | 17 +--
branches/quickbook-filenames/tools/quickbook/src/quickbook.hpp | 4
branches/quickbook-filenames/tools/quickbook/src/values_parse.hpp | 174 ++++-----------------------------------
11 files changed, 270 insertions(+), 370 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:35:03 EST (Tue, 22 Feb 2011)
@@ -262,8 +262,6 @@
fully_qualified_id(actions.doc_id, actions.qualified_section_id, id);
}
- actions.output_pre(actions.out);
- actions.anchors.swap(actions.saved_anchors);
actions.anchors.push_back(anchor);
actions.output_pre(actions.out);
@@ -289,10 +287,10 @@
out << post;
}
- cond_phrase_push::cond_phrase_push(quickbook::actions& actions)
- : actions(actions)
- , saved_suppress(actions.suppress)
+ void cond_phrase_push::start()
{
+ saved_suppress = actions.suppress;
+
value_consumer values = actions.values.get();
bool condition = find(actions.macro,
values.consume().get_quickbook().c_str());
@@ -300,7 +298,7 @@
actions.suppress = actions.suppress || !condition;
}
- cond_phrase_push::~cond_phrase_push()
+ void cond_phrase_push::cleanup()
{
actions.suppress = saved_suppress;
}
@@ -1359,6 +1357,9 @@
actions.qualified_section_id += actions.section_id;
++actions.section_level;
+ actions::string_list saved_anchors;
+ saved_anchors.swap(actions.anchors);
+
actions.output_pre(actions.out);
if (qbk_version_n < 103) // version 1.2 and below
@@ -1372,7 +1373,7 @@
<< "." << actions.qualified_section_id << "\">\n";
}
- actions.anchors.swap(actions.saved_anchors);
+ actions.anchors.swap(saved_anchors);
actions.output_pre(actions.out);
if (qbk_version_n < 103) // version 1.2 and below
@@ -1638,32 +1639,15 @@
return (*this)(first, last, value::default_tag);
}
- void phrase_to_value_action::operator()(iterator first, iterator last) const
+ void collector_to_value_action::operator()(iterator first, iterator last) const
{
- if(!actions.output_pre(actions.phrase)) return;
+ if(!actions.output_pre(output)) return;
std::string value;
- actions.phrase.swap(value);
- actions.values.builder.insert(
- bbk_value(value, value::default_tag));
+ output.swap(value);
+ actions.values.builder.insert(bbk_value(value, value::default_tag));
}
- void inner_phrase_action_pre::operator()(iterator, iterator) const
- {
- // TODO: Really?
- if(actions.suppress) return;
-
- actions.saved_anchors.clear();
- actions.saved_anchors.swap(actions.anchors);
- }
-
- void inner_phrase_action_post::operator()(iterator, iterator) const
- {
- if(actions.suppress) return;
-
- actions.output_pre(actions.phrase);
- }
-
bool pre_output_action::operator()(collector& tgt) const
{
if(actions.suppress) return false;
@@ -1688,51 +1672,27 @@
return (*this)(actions.out);
}
- scoped_block_push::scoped_block_push(quickbook::actions& actions)
- : actions(actions)
+ void scoped_output_push::start()
{
actions.out.push();
actions.phrase.push();
+ actions.anchors.swap(saved_anchors);
}
- scoped_block_push::~scoped_block_push()
+ void scoped_output_push::cleanup()
{
actions.phrase.pop();
actions.out.pop();
+ actions.anchors.swap(saved_anchors);
}
- void scoped_block_push::success_impl()
- {
- actions.values.builder.insert(
- bbk_value(actions.out.str(), value::default_tag));
- }
-
- scoped_phrase_push::scoped_phrase_push(quickbook::actions& actions)
- : actions(actions)
- {
- actions.out.push();
- actions.phrase.push();
- }
-
- scoped_phrase_push::~scoped_phrase_push()
- {
- actions.phrase.pop();
- actions.out.pop();
- }
-
- void scoped_phrase_push::success_impl()
- {
- actions.values.builder.insert(
- bbk_value(actions.phrase.str(), value::default_tag));
- }
-
- set_no_eols_scoped::set_no_eols_scoped(quickbook::actions& actions)
- : actions(actions), saved_no_eols(actions.no_eols)
+ void set_no_eols_scoped::start()
{
+ saved_no_eols = actions.no_eols;
actions.no_eols = false;
}
- set_no_eols_scoped::~set_no_eols_scoped()
+ void set_no_eols_scoped::cleanup()
{
actions.no_eols = saved_no_eols;
}
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:35:03 EST (Tue, 22 Feb 2011)
@@ -24,6 +24,7 @@
#include "template_stack.hpp"
#include "utils.hpp"
#include "values.hpp"
+#include "scoped.hpp"
#ifdef BOOST_MSVC
// disable copy/assignment could not be generated, unreferenced formal params
@@ -74,14 +75,6 @@
actions& escape_actions,
std::string const& source_mode);
- struct scoped_action_base
- {
- typedef quickbook::actions data_type;
-
- template <typename T> void success(T const&) {}
- void failure() {}
- };
-
struct error_message_action
{
// Prints an error message to std::cerr
@@ -227,8 +220,11 @@
struct cond_phrase_push : scoped_action_base
{
- cond_phrase_push(quickbook::actions&);
- ~cond_phrase_push();
+ cond_phrase_push(quickbook::actions& x)
+ : actions(x) {}
+
+ void start();
+ void cleanup();
quickbook::actions& actions;
bool saved_suppress;
@@ -636,8 +632,8 @@
struct phrase_to_docinfo_action_impl
{
- template <typename Arg1, typename Arg2, typename Arg3 = void>
- struct result { typedef void type; };
+ template <typename Arg1, typename Arg2, typename Arg3 = void>
+ struct result { typedef void type; };
phrase_to_docinfo_action_impl(quickbook::actions& actions)
: actions(actions) {}
@@ -650,34 +646,15 @@
typedef phoenix::function<phrase_to_docinfo_action_impl> phrase_to_docinfo_action;
- struct phrase_to_value_action
+ struct collector_to_value_action
{
- phrase_to_value_action(quickbook::actions& actions)
- : actions(actions) {}
+ collector_to_value_action(quickbook::actions& actions, collector& output)
+ : actions(actions), output(output) {}
void operator()(iterator first, iterator last) const;
quickbook::actions& actions;
- };
-
- struct inner_phrase_action_pre
- {
- inner_phrase_action_pre(quickbook::actions& actions)
- : actions(actions) {}
-
- void operator()(iterator, iterator) const;
-
- quickbook::actions& actions;
- };
-
- struct inner_phrase_action_post
- {
- inner_phrase_action_post(quickbook::actions& actions)
- : actions(actions) {}
-
- void operator()(iterator, iterator) const;
-
- quickbook::actions& actions;
+ collector& output;
};
struct pre_output_action
@@ -691,30 +668,25 @@
quickbook::actions& actions;
};
- struct scoped_block_push : scoped_action_base
+ struct scoped_output_push : scoped_action_base
{
- scoped_block_push(quickbook::actions&);
- ~scoped_block_push();
- template <typename T> void success(T const&) { this->success_impl(); }
- void success_impl();
+ scoped_output_push(quickbook::actions& actions)
+ : actions(actions) {}
- quickbook::actions& actions;
- };
-
- struct scoped_phrase_push : scoped_action_base
- {
- scoped_phrase_push(quickbook::actions&);
- ~scoped_phrase_push();
- template <typename T> void success(T const&) { this->success_impl(); }
- void success_impl();
+ void start();
+ void cleanup();
quickbook::actions& actions;
+ std::vector<std::string> saved_anchors;
};
struct set_no_eols_scoped : scoped_action_base
{
- set_no_eols_scoped(quickbook::actions&);
- ~set_no_eols_scoped();
+ set_no_eols_scoped(quickbook::actions& actions)
+ : actions(actions) {}
+
+ void start();
+ void cleanup();
quickbook::actions& actions;
bool saved_no_eols;
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:35:03 EST (Tue, 22 Feb 2011)
@@ -23,10 +23,6 @@
actions::actions(fs::path const& filein_, fs::path const& outdir_, string_stream& out_)
: grammar_()
- , values()
- , phrase_value(*this)
- , docinfo_value(*this)
-
// header info
, doc_type()
, doc_title_qbk()
@@ -40,6 +36,15 @@
, phrase()
, list_buffer()
+ // value actions
+ , values()
+ , phrase_value(*this, phrase)
+ , out_value(*this, out)
+ , docinfo_value(*this)
+ , scoped_cond_phrase(*this)
+ , scoped_output(*this)
+ , scoped_no_eols(*this)
+
// state
, filename(fs::absolute(filein_))
, outdir(outdir_)
@@ -59,7 +64,6 @@
, templates()
, error_count(0)
, anchors()
- , saved_anchors()
, no_eols(true)
, suppress(false)
, warned_about_breaks(false)
@@ -67,20 +71,16 @@
// actions
, element(*this)
, error(*this)
- , scoped_block(*this)
- , scoped_phrase(*this)
, code(out, phrase, *this)
, code_block(phrase, phrase, *this)
, inline_code(phrase, *this)
, inside_paragraph(out, phrase, paragraph_pre, paragraph_post, *this)
, hr(out, hr_, *this)
- , set_no_eols(*this)
, space_char(phrase)
, plain_char(phrase, *this)
, raw_char(phrase, *this)
, escape_unicode(phrase, *this)
, image(phrase, *this)
- , scoped_cond_phrase(*this)
, list(out, list_buffer, list_indent, list_marks, *this)
, list_format(list_buffer, list_indent, list_marks, error_count, *this)
@@ -138,8 +138,6 @@
, escape_pre(phrase, escape_pre_, *this)
, escape_post(phrase, escape_post_, *this)
- , inner_phrase_pre(*this)
- , inner_phrase_post(*this)
, output_pre(*this)
{
// turn off __FILENAME__ macro on debug mode = true
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:35:03 EST (Tue, 22 Feb 2011)
@@ -38,10 +38,6 @@
typedef std::pair<char, int> mark_type;
static int const max_template_depth = 100;
- value_parser values;
- phrase_to_value_action phrase_value;
- phrase_to_docinfo_action docinfo_value;
-
// header info
std::string doc_type;
std::string doc_title_qbk;
@@ -55,6 +51,19 @@
collector phrase;
collector list_buffer;
+ // value actions
+ value_parser values;
+ collector_to_value_action phrase_value;
+ collector_to_value_action out_value;
+ phrase_to_docinfo_action docinfo_value;
+
+ scoped_parser<cond_phrase_push>
+ scoped_cond_phrase;
+ scoped_parser<scoped_output_push>
+ scoped_output;
+ scoped_parser<set_no_eols_scoped>
+ scoped_no_eols;
+
// state
fs::path filename;
fs::path outdir;
@@ -89,7 +98,6 @@
template_stack templates;
int error_count;
string_list anchors;
- string_list saved_anchors;
bool no_eols;
bool suppress;
bool warned_about_breaks;
@@ -106,26 +114,17 @@
element_action element;
error_action error;
-
- scoped_parser<scoped_block_push>
- scoped_block;
- scoped_parser<scoped_phrase_push>
- scoped_phrase;
code_action code;
code_action code_block;
inline_code_action inline_code;
implicit_paragraph_action inside_paragraph;
markup_action hr;
- scoped_parser<set_no_eols_scoped>
- set_no_eols;
space space_char;
plain_char_action plain_char;
raw_char_action raw_char;
escape_unicode_action escape_unicode;
image_action image;
- scoped_parser<cond_phrase_push>
- scoped_cond_phrase;
list_action list;
list_format_action list_format;
@@ -183,8 +182,6 @@
markup_action escape_pre;
markup_action escape_post;
- inner_phrase_action_pre inner_phrase_pre;
- inner_phrase_action_post inner_phrase_post;
pre_output_action output_pre;
};
}
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:35:03 EST (Tue, 22 Feb 2011)
@@ -17,6 +17,7 @@
#include <boost/spirit/include/classic_if.hpp>
#include <boost/spirit/include/classic_clear_actor.hpp>
#include <boost/spirit/include/phoenix1_primitives.hpp>
+#include <boost/spirit/include/phoenix1_casts.hpp>
namespace quickbook
{
@@ -122,7 +123,8 @@
local.preformatted =
space
>> !eol
- >> actions.set_no_eols[phrase] [actions.phrase_value]
+ >> actions.scoped_no_eols()
+ [phrase] [actions.phrase_value]
;
elements.add
@@ -204,7 +206,7 @@
local.varlistterm =
space
>> cl::ch_p('[')
- >> actions.values.save
+ >> actions.values.save()
[ phrase
>> cl::ch_p(']')
>> space
@@ -242,7 +244,9 @@
>>
(
(
- actions.values.list(table_tags::row)[*local.table_cell]
+ actions.values.list(table_tags::row)
+ [ *local.table_cell
+ ]
>> cl::ch_p(']')
>> space
)
@@ -293,11 +297,10 @@
;
local.inner_phrase =
- actions.values.save
- [ cl::eps_p [actions.inner_phrase_pre]
- >> phrase
- >> cl::eps_p [actions.inner_phrase_post]
- ] [actions.docinfo_value(ph::arg1, ph::arg2)]
+ actions.scoped_output()
+ [
+ phrase [actions.docinfo_value(ph::arg1, ph::arg2)]
+ ]
;
}
}
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:35:03 EST (Tue, 22 Feb 2011)
@@ -21,6 +21,7 @@
#include <boost/spirit/include/classic_if.hpp>
#include <boost/spirit/include/classic_loops.hpp>
#include <boost/spirit/include/phoenix1_primitives.hpp>
+#include <boost/spirit/include/phoenix1_casts.hpp>
namespace quickbook
{
@@ -186,7 +187,7 @@
| cl::eps_p [actions.error]
)
;
-
+
local.code =
(
local.code_line
@@ -357,14 +358,14 @@
simple_markup(local.simple_teletype,
'=', actions.simple_teletype, local.simple_phrase_end);
- phrase = actions.values.save[
+ phrase = actions.values.save()[
*( common
| (cl::anychar_p - phrase_end) [actions.plain_char]
)
]
;
- extended_phrase = actions.values.save[
+ extended_phrase = actions.values.save()[
*( local.extended_phrase_element
| common
| (cl::anychar_p - phrase_end) [actions.plain_char]
@@ -373,13 +374,15 @@
;
inside_paragraph =
- actions.scoped_block[
- actions.values.save[
+ actions.scoped_output()
+ [
+ actions.values.save()
+ [
(*( common
| (cl::anychar_p - phrase_end) [actions.plain_char]
| (+eol) [actions.inside_paragraph]
)) [actions.inside_paragraph]
- ]
+ ] [actions.out_value]
]
;
@@ -442,7 +445,7 @@
// Simple phrase grammar
//
- simple_phrase = actions.values.save[
+ simple_phrase = actions.values.save()[
*( common
| (cl::anychar_p - ']') [actions.plain_char]
)
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:35:03 EST (Tue, 22 Feb 2011)
@@ -90,27 +90,27 @@
const char* replaceable_pre_ = "<replaceable>";
const char* replaceable_post_ = "</replaceable>";
- namespace detail
- {
- std::map<value::tag_type, markup> markups;
+ 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 }
- };
+ 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;
- }
- }
- }
+ BOOST_FOREACH(markup m, init_markups)
+ {
+ markups[m.tag] = m;
+ }
+ }
+ }
}
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-02-22 15:35:03 EST (Tue, 22 Feb 2011)
@@ -14,39 +14,115 @@
#include <boost/spirit/include/classic_core.hpp>
#include <boost/spirit/include/classic_nil.hpp>
+#include <boost/spirit/include/phoenix1_tuples.hpp>
namespace quickbook {
namespace cl = boost::spirit::classic;
- // Used to store variables/state while parsing
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ // scoped_parser<Impl>
+ //
+ // Impl is a struct with the methods:
+ //
+ // void start();
+ // void success();
+ // void failure();
+ // void cleanup();
+ //
+ ///////////////////////////////////////////////////////////////////////////
- template <typename ScopeT, typename DataT, typename ParserT>
+ template <typename Impl, typename Arguments, typename ParserT>
struct scoped_parser_impl
- : public cl::unary< ParserT, cl::parser< scoped_parser_impl<ScopeT, DataT, ParserT> > >
+ : public cl::unary< ParserT, cl::parser< scoped_parser_impl<Impl, Arguments, ParserT> > >
{
- typedef scoped_parser_impl<ScopeT, DataT, ParserT> self_t;
- typedef cl::unary< ParserT, cl::parser< scoped_parser_impl<ScopeT, DataT, ParserT> > > base_t;
+ typedef scoped_parser_impl<Impl, Arguments, ParserT> self_t;
+ typedef cl::unary< ParserT, cl::parser< scoped_parser_impl<Impl, Arguments, ParserT> > > base_t;
template <typename ScannerT>
struct result { typedef cl::match<> type; };
- scoped_parser_impl(DataT& actions, ParserT const &p)
+ scoped_parser_impl(
+ Impl const& impl,
+ Arguments const& arguments,
+ ParserT const &p)
: base_t(p)
- , actions(actions)
+ , impl_(impl)
+ , arguments_(arguments)
{}
+ 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)
+ {}
+
+ typedef phoenix::tuple_index<0> t0;
+ typedef phoenix::tuple_index<1> t1;
+
+ void start(phoenix::tuple<> const&)
+ {
+ impl_.start();
+ in_progress_ = true;
+ }
+
+ template <typename Arg1>
+ void start(phoenix::tuple<Arg1> const& x)
+ {
+ impl_.start(x[t0()]);
+ in_progress_ = true;
+ }
+
+ template <typename Arg1, typename Arg2>
+ void start(phoenix::tuple<Arg1, Arg2> const& x)
+ {
+ impl_.start(x[t0()], x[t1()]);
+ in_progress_ = true;
+ }
+
+ void success()
+ {
+ in_progress_ = false;
+ impl_.success();
+ }
+
+ void failure()
+ {
+ in_progress_ = false;
+ impl_.failure();
+ }
+
+ ~scoped()
+ {
+ if (in_progress_) impl_.failure();
+ impl_.cleanup();
+ }
+
+ Impl impl_;
+ bool in_progress_;
+ };
+
template <typename ScannerT>
typename result<ScannerT>::type parse(ScannerT const &scan) const
{
typedef typename ScannerT::iterator_t iterator_t;
iterator_t save = scan.first;
- ScopeT scope(actions);
+ scoped scope(impl_);
+ scope.start(arguments_);
+
typename cl::parser_result<ParserT, ScannerT>::type result
= this->subject().parse(scan);
+ //result = scope.match(result);
+
if (result) {
- scope.success(result);
+ scope.success();
return scan.create_match(result.length(), cl::nil_t(), save, scan.first);
}
else {
@@ -55,30 +131,21 @@
}
}
- DataT& actions;
+ Impl impl_;
+ Arguments arguments_;
};
- ///////////////////////////////////////////////////////////////////////////
- //
- // scoped_parser
- //
- // generator for scoped_parser_impl objects
- // operator[] returns scoped_parser_impl according to its argument
- //
- ///////////////////////////////////////////////////////////////////////////
- template <typename ScopeT>
- struct scoped_parser
- {
- typedef typename ScopeT::data_type data_type;
-
- explicit scoped_parser(data_type& actions)
- : actions(actions) {}
+ template <typename Impl, typename Arguments>
+ struct scoped_parser_gen
+ {
+ explicit scoped_parser_gen(Impl impl, Arguments const& arguments)
+ : impl_(impl), arguments_(arguments) {}
template<typename ParserT>
scoped_parser_impl
<
- ScopeT,
- data_type,
+ Impl,
+ Arguments,
typename cl::as_parser<ParserT>::type
>
operator[](ParserT const &p) const
@@ -86,17 +153,56 @@
typedef cl::as_parser<ParserT> as_parser_t;
typedef typename as_parser_t::type parser_t;
- return scoped_parser_impl<ScopeT, data_type, parser_t>
- (actions, as_parser_t::convert(p));
+ return scoped_parser_impl<Impl, Arguments, parser_t>
+ (impl_, arguments_, p);
}
+
+ Impl impl_;
+ Arguments arguments_;
+ };
+
+ template <typename Impl>
+ struct scoped_parser
+ {
+ scoped_parser(Impl const& impl)
+ : impl_(impl) {}
+
+ scoped_parser_gen<Impl, phoenix::tuple<> >
+ operator()() const
+ {
+ typedef phoenix::tuple<> tuple;
+ return scoped_parser_gen<Impl, tuple>(impl_, tuple());
+ };
+
+ template <typename Arg1>
+ scoped_parser_gen<Impl, phoenix::tuple<Arg1> >
+ operator()(Arg1 x1) const
+ {
+ typedef phoenix::tuple<Arg1> tuple;
+ return scoped_parser_gen<Impl, tuple>(impl_, tuple(x1));
+ };
+
+ template <typename Arg1, typename Arg2>
+ scoped_parser_gen<Impl, phoenix::tuple<Arg1, Arg2> >
+ operator()(Arg1 x1, Arg2 x2) const
+ {
+ typedef phoenix::tuple<Arg1, Arg2> tuple;
+ return scoped_parser_gen<Impl, tuple>(impl_, tuple(x1, x2));
+ };
- data_type& actions;
+ Impl impl_;
};
+ ///////////////////////////////////////////////////////////////////////////
+ //
// Lookback parser
//
+ // usage: lookback[body]
+ //
// Requires that iterator has typedef 'lookback_range' and function
// 'lookback' returning a 'lookback_range'.
+ //
+ ///////////////////////////////////////////////////////////////////////////
template <typename ParserT>
struct lookback_parser
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:35:03 EST (Tue, 22 Feb 2011)
@@ -16,6 +16,7 @@
#include <boost/spirit/include/classic_clear_actor.hpp>
#include <boost/spirit/include/classic_if.hpp>
#include <boost/spirit/include/phoenix1_primitives.hpp>
+#include <boost/spirit/include/phoenix1_casts.hpp>
namespace quickbook
{
@@ -48,7 +49,8 @@
local.cond_phrase =
blank
>> macro_identifier [actions.values.entry(ph::arg1, ph::arg2)]
- >> actions.scoped_cond_phrase[extended_phrase]
+ >> actions.scoped_cond_phrase()
+ [extended_phrase]
;
elements.add
@@ -63,8 +65,8 @@
>> +(cl::anychar_p - (cl::space_p | phrase_end | '['))
)) [actions.values.entry(ph::arg1, ph::arg2)]
>> hard_space
- >> *actions.values.list()[
- '['
+ >> *actions.values.list()
+ [ '['
>> (*(cl::alnum_p | '_'))
[actions.values.entry(ph::arg1, ph::arg2)]
>> space
@@ -252,12 +254,9 @@
;
local.inner_phrase =
- actions.scoped_phrase[
- actions.values.save
- [ cl::eps_p [actions.inner_phrase_pre]
- >> phrase
- >> cl::eps_p [actions.inner_phrase_post]
- ] [actions.phrase_value]
+ blank >>
+ actions.scoped_output()
+ [ phrase [actions.phrase_value]
]
;
}
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:35:03 EST (Tue, 22 Feb 2011)
@@ -35,8 +35,8 @@
// Declared here to avoid including other headers
namespace detail
{
- void initialise_markups();
- }
+ void initialise_markups();
+ }
}
#endif
Added: branches/quickbook-filenames/tools/quickbook/src/scoped.hpp
==============================================================================
--- (empty file)
+++ branches/quickbook-filenames/tools/quickbook/src/scoped.hpp 2011-02-22 15:35:03 EST (Tue, 22 Feb 2011)
@@ -0,0 +1,25 @@
+/*=============================================================================
+ Copyright (c) 2011 Daniel James
+
+ Use, modification and distribution is subject to the Boost Software
+ License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+
+#if !defined(BOOST_QUICKBOOK_SCOPED_HPP)
+#define BOOST_QUICKBOOK_SCOPED_HPP
+
+#include <cassert>
+
+namespace quickbook {
+
+ struct scoped_action_base
+ {
+ void start() {}
+ void success() {}
+ void failure() {}
+ void cleanup() {}
+ };
+}
+
+#endif
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:35:03 EST (Tue, 22 Feb 2011)
@@ -10,176 +10,38 @@
#define BOOST_SPIRIT_QUICKBOOK_VALUES_PARSE_HPP
#include "values.hpp"
-#include <boost/spirit/include/classic_core.hpp>
+#include "parsers.hpp"
#include <boost/spirit/include/phoenix1_functions.hpp>
-#include <boost/spirit/include/phoenix1_primitives.hpp>
+
+#include <iostream>
namespace quickbook {
- namespace cl = boost::spirit::classic;
namespace ph = phoenix;
struct value_builder_save
{
- value_builder_save(value_builder& a) : a(a) { a.save(); }
- ~value_builder_save() { a.restore(); }
- value_builder& a;
- };
-
- template <typename ParserT>
- struct value_save_parser
- : public cl::unary< ParserT, cl::parser< value_save_parser<ParserT> > >
- {
- typedef value_save_parser<ParserT> self_t;
- typedef cl::unary< ParserT, cl::parser< value_save_parser<ParserT> > > base_t;
-
- template <typename ScannerT>
- struct result
- {
- typedef typename cl::parser_result<ParserT, ScannerT>::type type;
- };
-
- value_save_parser(value_builder& a, ParserT const &p)
- : base_t(p)
- , builder_(a)
- {}
-
- template <typename ScannerT>
- typename result<ScannerT>::type parse(ScannerT const &scan) const
- {
- typedef typename ScannerT::iterator_t iterator_t;
- iterator_t save = scan.first;
+ value_builder_save(value_builder& builder) : builder(builder) {}
- value_builder_save saver(builder_);
+ void start() { builder.save(); }
+ void success() {}
+ void failure() {}
+ void cleanup() { builder.restore(); }
- typename cl::parser_result<ParserT, ScannerT>::type result
- = this->subject().parse(scan);
-
- if (result) {
- return scan.create_match(result.length(), cl::nil_t(), save, scan.first);
- }
- else {
- return scan.no_match();
- }
- }
-
- value_builder& builder_;
- };
-
- struct value_save_gen
- {
- explicit value_save_gen(value_builder& b)
- : builder_(b) {}
-
- template<typename ParserT>
- value_save_parser<typename cl::as_parser<ParserT>::type>
- operator[](ParserT const& p) const
- {
- typedef typename cl::as_parser<ParserT> as_parser_t;
- typedef typename as_parser_t::type parser_t;
-
- return value_save_parser<parser_t>
- (builder_, as_parser_t::convert(p));
- }
-
- value_builder& builder_;
+ value_builder& builder;
};
struct value_builder_list
{
- value_builder_list(value_builder& a, value::tag_type t)
- : a(a), finished(false) { a.start_list(t); }
- void finish() { a.finish_list(); finished = true; }
- ~value_builder_list() { if(!finished) a.clear_list(); }
- value_builder& a;
- bool finished;
- };
-
- template <typename TagActor, typename ParserT>
- struct value_scoped_list_parser
- : public cl::unary< ParserT, cl::parser< value_scoped_list_parser<TagActor, ParserT> > >
- {
- typedef value_scoped_list_parser<TagActor, ParserT> self_t;
- typedef cl::unary< ParserT, cl::parser<self_t> > base_t;
+ value_builder_list(value_builder& builder) : builder(builder) {}
- template <typename ScannerT>
- struct result
- {
- typedef typename cl::parser_result<ParserT, ScannerT>::type type;
- };
-
- value_scoped_list_parser(value_builder& a, TagActor k, ParserT const &p)
- : base_t(p)
- , builder_(a)
- , tag_(k)
- {}
+ void start(value::tag_type tag = value::default_tag)
+ { builder.start_list(tag); }
- template <typename ScannerT>
- typename result<ScannerT>::type parse(ScannerT const &scan) const
- {
- typedef typename ScannerT::iterator_t iterator_t;
- iterator_t save = scan.first;
- value_builder_list list(builder_, tag_());
- typename cl::parser_result<ParserT, ScannerT>::type result
- = this->subject().parse(scan);
-
- if (result) {
- list.finish();
- return scan.create_match(result.length(), cl::nil_t(), save, scan.first);
- }
- else {
- return scan.no_match();
- }
- }
-
- value_builder& builder_;
- TagActor tag_;
- };
+ void success() { builder.finish_list(); }
+ void failure() { builder.clear_list(); }
+ void cleanup() {}
- template <typename TagActor>
- struct value_scoped_list_gen2
- {
- explicit value_scoped_list_gen2(value_builder& b, TagActor t)
- : b(b), tag_(t) {}
-
- template<typename ParserT>
- value_scoped_list_parser<TagActor, typename cl::as_parser<ParserT>::type>
- operator[](ParserT const& p) const
- {
- typedef typename cl::as_parser<ParserT> as_parser_t;
- typedef typename as_parser_t::type parser_t;
-
- return value_scoped_list_parser<TagActor, parser_t>
- (b, tag_, as_parser_t::convert(p));
- }
-
- value_builder& b;
- TagActor tag_;
- };
-
- struct value_scoped_list_gen
- {
- template <typename Arg1> struct result { typedef void type; };
- typedef void result_type;
-
- explicit value_scoped_list_gen(value_builder& b)
- : b(b) {}
-
- template <typename T>
- value_scoped_list_gen2<typename ph::as_actor<T>::type>
- operator()(T const& tag) const
- {
- return value_scoped_list_gen2<typename ph::as_actor<T>::type>(
- b, ph::as_actor<T>::convert(tag));
- }
-
- value_scoped_list_gen2<ph::as_actor<value::tag_type>::type>
- operator()(value::tag_type tag = value::default_tag) const
- {
- return value_scoped_list_gen2<ph::as_actor<value::tag_type>::type>(
- b, ph::as_actor<value::tag_type>::convert(tag));
- }
-
- value_builder& b;
+ value_builder& builder;
};
struct value_entry
@@ -252,8 +114,8 @@
value get() { return builder.get(); }
value_builder builder;
- value_save_gen save;
- value_scoped_list_gen list;
+ scoped_parser<value_builder_save> save;
+ scoped_parser<value_builder_list> list;
ph::function<value_entry> entry;
ph::function<value_reset> reset;
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