|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r75358 - branches/quickbook-dev/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-11-06 17:21:51
Author: danieljames
Date: 2011-11-06 17:21:50 EST (Sun, 06 Nov 2011)
New Revision: 75358
URL: http://svn.boost.org/trac/boost/changeset/75358
Log:
Quickbook: Clean up some of the value parser stuff.
Since values are now used in most places, a lot of the complexity became
unnecessary. Some of the string stuff in values.cpp is now redundant,
but I'll leave it alone for now.
Text files modified:
branches/quickbook-dev/tools/quickbook/src/actions.cpp | 33 +++++++-----------------
branches/quickbook-dev/tools/quickbook/src/actions.hpp | 44 +++----------------------------
branches/quickbook-dev/tools/quickbook/src/actions_class.cpp | 4 --
branches/quickbook-dev/tools/quickbook/src/actions_class.hpp | 7 +---
branches/quickbook-dev/tools/quickbook/src/block_element_grammar.cpp | 14 +++++-----
branches/quickbook-dev/tools/quickbook/src/doc_info_grammar.cpp | 23 ++++++++--------
branches/quickbook-dev/tools/quickbook/src/main_grammar.cpp | 54 +++++++++++++++++++--------------------
branches/quickbook-dev/tools/quickbook/src/parsers.hpp | 9 +++--
branches/quickbook-dev/tools/quickbook/src/phrase_element_grammar.cpp | 4 --
branches/quickbook-dev/tools/quickbook/src/scoped.hpp | 3 +
branches/quickbook-dev/tools/quickbook/src/values_parse.hpp | 18 ------------
11 files changed, 71 insertions(+), 142 deletions(-)
Modified: branches/quickbook-dev/tools/quickbook/src/actions.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions.cpp 2011-11-06 17:21:50 EST (Sun, 06 Nov 2011)
@@ -1947,23 +1947,17 @@
}
}
- void phrase_to_docinfo_action_impl::operator()(parse_iterator first, parse_iterator last,
- value::tag_type tag) const
+ bool to_value_scoped_action::start(value::tag_type t)
{
- write_anchors(actions, actions.phrase);
+ actions.out.push();
+ actions.phrase.push();
+ actions.anchors.swap(saved_anchors);
+ tag = t;
- std::string encoded;
- actions.phrase.swap(encoded);
- actions.values.builder.insert(
- qbk_bbk_value(actions.current_file, first.base(), last.base(), encoded, tag));
+ return true;
}
- void phrase_to_docinfo_action_impl::operator()(parse_iterator first, parse_iterator last) const
- {
- return (*this)(first, last, value::default_tag);
- }
-
- void to_value_action::operator()(parse_iterator, parse_iterator) const
+ void to_value_scoped_action::success(parse_iterator first, parse_iterator last)
{
std::string value;
@@ -1979,19 +1973,12 @@
actions.phrase.swap(value);
}
- actions.values.builder.insert(bbk_value(value, tag));
+ actions.values.builder.insert(qbk_bbk_value(
+ actions.current_file, first.base(), last.base(), value, tag));
}
- bool scoped_output_push::start()
- {
- actions.out.push();
- actions.phrase.push();
- actions.anchors.swap(saved_anchors);
-
- return true;
- }
- void scoped_output_push::cleanup()
+ void to_value_scoped_action::cleanup()
{
actions.phrase.pop();
actions.out.pop();
Modified: branches/quickbook-dev/tools/quickbook/src/actions.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions.hpp 2011-11-06 17:21:50 EST (Sun, 06 Nov 2011)
@@ -12,8 +12,6 @@
#include <string>
#include <vector>
-#include <boost/spirit/include/phoenix1_functions.hpp>
-#include <boost/spirit/include/classic_symbols_fwd.hpp>
#include "fwd.hpp"
#include "template_stack.hpp"
#include "utils.hpp"
@@ -23,8 +21,6 @@
namespace quickbook
{
- namespace cl = boost::spirit::classic;
-
extern unsigned qbk_version_n; // qbk_major_version * 100 + qbk_minor_version
struct quickbook_range {
@@ -293,48 +289,18 @@
void pre(collector& out, quickbook::actions& actions, value include_doc_id, docinfo_types);
void post(collector& out, quickbook::actions& actions, docinfo_types);
- struct phrase_to_docinfo_action_impl
+ struct to_value_scoped_action : scoped_action_base
{
- template <typename Arg1, typename Arg2, typename Arg3 = void>
- struct result { typedef void type; };
-
- phrase_to_docinfo_action_impl(quickbook::actions& actions)
+ to_value_scoped_action(quickbook::actions& actions)
: actions(actions) {}
- void operator()(parse_iterator first, parse_iterator last) const;
- void operator()(parse_iterator first, parse_iterator last, value::tag_type) const;
-
- quickbook::actions& actions;
- };
-
- typedef phoenix::function<phrase_to_docinfo_action_impl> phrase_to_docinfo_action;
-
- struct to_value_action
- {
- to_value_action(quickbook::actions& actions, int tag = value::default_tag)
- : actions(actions)
- , tag(tag)
- {}
-
- void operator()(parse_iterator first, parse_iterator last) const;
-
- to_value_action operator()(int tag)
- { return to_value_action(actions, tag); }
-
- quickbook::actions& actions;
- int tag;
- };
-
- struct scoped_output_push : scoped_action_base
- {
- scoped_output_push(quickbook::actions& actions)
- : actions(actions) {}
-
- bool start();
+ bool start(value::tag_type = value::default_tag);
+ void success(parse_iterator, parse_iterator);
void cleanup();
quickbook::actions& actions;
std::vector<std::string> saved_anchors;
+ value::tag_type tag;
};
struct set_no_eols_scoped : scoped_action_base
Modified: branches/quickbook-dev/tools/quickbook/src/actions_class.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions_class.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions_class.cpp 2011-11-06 17:21:50 EST (Sun, 06 Nov 2011)
@@ -48,11 +48,9 @@
, out(out_)
, phrase()
, values(¤t_file)
- , to_value(*this)
- , docinfo_value(*this)
+ , to_value(*this)
, scoped_cond_phrase(*this)
- , scoped_output(*this)
, scoped_no_eols(*this)
, element(*this)
Modified: branches/quickbook-dev/tools/quickbook/src/actions_class.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions_class.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions_class.hpp 2011-11-06 17:21:50 EST (Sun, 06 Nov 2011)
@@ -77,13 +77,10 @@
// actions
///////////////////////////////////////////////////////////////////////////
- to_value_action to_value;
- phrase_to_docinfo_action docinfo_value;
-
+ scoped_parser<to_value_scoped_action>
+ to_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;
Modified: branches/quickbook-dev/tools/quickbook/src/block_element_grammar.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/block_element_grammar.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/block_element_grammar.cpp 2011-11-06 17:21:50 EST (Sun, 06 Nov 2011)
@@ -237,13 +237,13 @@
>> (*(cl::anychar_p - eol)) [actions.values.entry(ph::arg1, ph::arg2, table_tags::title)]
>> (+eol)
| cl::eps_p(qbk_since(106))
- >> actions.scoped_output()
+ >> actions.to_value(table_tags::title)
[
- (*(escape
+ *(escape
| line_comment
| (cl::anychar_p - (*(line_comment | cl::blank_p) >> (cl::eol_p | '[' | ']')))
[actions.plain_char]
- )) [actions.docinfo_value(ph::arg1, ph::arg2, table_tags::title)]
+ )
]
>> (*eol)
;
@@ -294,16 +294,16 @@
;
local.inner_block =
- actions.scoped_output()
+ actions.to_value()
[
- inside_paragraph [actions.to_value]
+ inside_paragraph
]
;
local.inner_phrase =
- actions.scoped_output()
+ actions.to_value()
[
- paragraph_phrase [actions.docinfo_value(ph::arg1, ph::arg2)]
+ paragraph_phrase
]
;
}
Modified: branches/quickbook-dev/tools/quickbook/src/doc_info_grammar.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/doc_info_grammar.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/doc_info_grammar.cpp 2011-11-06 17:21:50 EST (Sun, 06 Nov 2011)
@@ -108,11 +108,10 @@
space
>> '[' >> space
>> (local.doc_types >> cl::eps_p)
- [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.docinfo_value(ph::arg1, ph::arg2, doc_info_tags::title)]
+ >> actions.to_value(doc_info_tags::title)
+ [ *(~cl::eps_p(cl::ch_p('[') | ']' | cl::eol_p) >> local.char_) ]
>> !(
space >> '[' >>
local.quickbook_version
@@ -157,7 +156,7 @@
// TODO: Restrictions on doc_id and doc_dirname?
- local.doc_simple = (*(~cl::eps_p(']') >> local.char_)) [actions.docinfo_value(ph::arg1, ph::arg2)];
+ local.doc_simple = actions.to_value() [*(~cl::eps_p(']') >> local.char_)];
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;
@@ -187,7 +186,7 @@
>> !cl::ch_p(',')
>> space
)
- >> local.doc_copyright_holder [actions.docinfo_value(ph::arg1, ph::arg2, doc_info_tags::copyright_name)]
+ >> actions.to_value(doc_info_tags::copyright_name) [ local.doc_copyright_holder ]
>> !cl::ch_p(',')
>> space
)
@@ -195,18 +194,18 @@
local.attribute_rules[doc_info_attributes::copyright] = &local.doc_copyright;
- local.doc_phrase = nested_phrase [actions.docinfo_value(ph::arg1, ph::arg2)];
+ local.doc_phrase = actions.to_value() [ nested_phrase ];
local.attribute_rules[doc_info_attributes::purpose] = &local.doc_phrase;
local.attribute_rules[doc_info_attributes::license] = &local.doc_phrase;
local.doc_author =
'['
>> space
- >> (*(~cl::eps_p(',') >> local.char_))
- [actions.docinfo_value(ph::arg1, ph::arg2, doc_info_tags::author_surname)]
+ >> actions.to_value(doc_info_tags::author_surname)
+ [*(~cl::eps_p(',') >> local.char_)]
>> ',' >> space
- >> (*(~cl::eps_p(']') >> local.char_))
- [actions.docinfo_value(ph::arg1, ph::arg2, doc_info_tags::author_first)]
+ >> actions.to_value(doc_info_tags::author_first)
+ [*(~cl::eps_p(']') >> local.char_)]
>> ']'
;
@@ -232,8 +231,8 @@
local.doc_biblioid =
(+cl::alnum_p) [actions.values.entry(ph::arg1, ph::arg2, doc_info_tags::biblioid_class)]
>> hard_space
- >> (+(~cl::eps_p(']') >> local.char_))
- [actions.docinfo_value(ph::arg1, ph::arg2, doc_info_tags::biblioid_value)]
+ >> actions.to_value(doc_info_tags::biblioid_value)
+ [+(~cl::eps_p(']') >> local.char_)]
;
local.attribute_rules[doc_info_attributes::biblioid] = &local.doc_biblioid;
Modified: branches/quickbook-dev/tools/quickbook/src/main_grammar.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/main_grammar.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/main_grammar.cpp 2011-11-06 17:21:50 EST (Sun, 06 Nov 2011)
@@ -70,7 +70,7 @@
return true;
}
- void success() { l.element_type = info_.type; }
+ void success(parse_iterator, parse_iterator) { l.element_type = info_.type; }
void failure() { l.element_type = element_info::nothing; }
main_grammar_local& l;
@@ -175,27 +175,30 @@
// brackets.
nested_phrase =
actions.values.save()
- [*( ~cl::eps_p(']')
- >> local.common(element_info::in_phrase)
- )]
+ [ *( ~cl::eps_p(']')
+ >> local.common(element_info::in_phrase)
+ )
+ ]
;
// paragraph_phrase is like a nested_phrase but is also terminated
// by a paragraph end.
paragraph_phrase =
actions.values.save()
- [*( ~cl::eps_p(phrase_end)
- >> local.common(element_info::in_phrase)
- )]
+ [ *( ~cl::eps_p(phrase_end)
+ >> local.common(element_info::in_phrase)
+ )
+ ]
;
// extended_phrase is like a paragraph_phrase but allows some block
// elements.
extended_phrase =
actions.values.save()
- [*( ~cl::eps_p(phrase_end)
- >> local.common(element_info::in_conditional)
- )]
+ [ *( ~cl::eps_p(phrase_end)
+ >> local.common(element_info::in_conditional)
+ )
+ ]
;
// inline_phrase is used a phrase that isn't nested inside
@@ -296,18 +299,14 @@
local.list =
cl::eps_p(cl::ch_p('*') | '#')
- [actions.values.reset()]
- >> actions.scoped_output()
- [
- actions.values.list(block_tags::list)
+ >> actions.values.list(block_tags::list)
[ +actions.values.list()
[ (*cl::blank_p) [actions.values.entry(ph::arg1, ph::arg2, general_tags::list_indent)]
>> (cl::ch_p('*') | '#')
[actions.values.entry(ph::arg1, ph::arg2, general_tags::list_mark)]
>> *cl::blank_p
- >> local.list_item [actions.to_value]
+ >> actions.to_value() [ local.list_item ]
]
- ]
] [actions.element]
;
@@ -475,18 +474,17 @@
]
>> actions.values.save()
[
- actions.scoped_output()
+ actions.to_value()
[
- ( cl::eps_p(actions.macro >> local.simple_markup_end)
- >> actions.macro [actions.do_macro]
- | ~cl::eps_p(cl::f_ch_p(local.simple_markup.mark))
- >> +( ~cl::eps_p
- ( lookback [~cl::f_ch_p(local.simple_markup.mark)]
- >> local.simple_markup_end
- )
- >> cl::anychar_p [actions.plain_char]
+ cl::eps_p(actions.macro >> local.simple_markup_end)
+ >> actions.macro [actions.do_macro]
+ | ~cl::eps_p(cl::f_ch_p(local.simple_markup.mark))
+ >> +( ~cl::eps_p
+ ( lookback [~cl::f_ch_p(local.simple_markup.mark)]
+ >> local.simple_markup_end
)
- ) [actions.to_value]
+ >> cl::anychar_p [actions.plain_char]
+ )
]
>> cl::f_ch_p(local.simple_markup.mark)
[actions.simple_markup]
@@ -539,10 +537,10 @@
>> *cl::space_p
>> ( '='
>> *cl::space_p
- >> inline_phrase
+ >> actions.to_value() [ inline_phrase ]
>> *cl::space_p
| cl::eps_p
- ) [actions.to_value]
+ )
] [actions.element]
;
Modified: branches/quickbook-dev/tools/quickbook/src/parsers.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/parsers.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/parsers.hpp 2011-11-06 17:21:50 EST (Sun, 06 Nov 2011)
@@ -28,7 +28,7 @@
// Impl is a struct with the methods:
//
// void start();
- // void success();
+ // void success(parse_iterator, parse_iterator);
// void failure();
// void cleanup();
//
@@ -83,10 +83,10 @@
return in_progress_;
}
- void success()
+ void success(parse_iterator f, parse_iterator l)
{
in_progress_ = false;
- impl_.success();
+ impl_.success(f, l);
}
void failure()
@@ -121,7 +121,8 @@
bool success = scope.impl_.result(result, scan);
if (success) {
- scope.success();
+ scope.success(save, scan.first);
+
if (result) {
return scan.create_match(result.length(), cl::nil_t(), save, scan.first);
}
Modified: branches/quickbook-dev/tools/quickbook/src/phrase_element_grammar.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/phrase_element_grammar.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/phrase_element_grammar.cpp 2011-11-06 17:21:50 EST (Sun, 06 Nov 2011)
@@ -138,9 +138,7 @@
local.inner_phrase =
blank
- >> actions.scoped_output()
- [ paragraph_phrase [actions.to_value]
- ]
+ >> actions.to_value() [ paragraph_phrase ]
;
}
}
Modified: branches/quickbook-dev/tools/quickbook/src/scoped.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/scoped.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/scoped.hpp 2011-11-06 17:21:50 EST (Sun, 06 Nov 2011)
@@ -16,7 +16,8 @@
struct scoped_action_base
{
bool start() { return true; }
- void success() {}
+ template <typename Iterator>
+ void success(Iterator, Iterator) {}
void failure() {}
void cleanup() {}
Modified: branches/quickbook-dev/tools/quickbook/src/values_parse.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/values_parse.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/values_parse.hpp 2011-11-06 17:21:50 EST (Sun, 06 Nov 2011)
@@ -44,7 +44,7 @@
return true;
}
- void success() { builder.finish_list(); }
+ void success(parse_iterator, parse_iterator) { builder.finish_list(); }
void failure() { builder.clear_list(); }
value_builder& builder;
@@ -76,20 +76,6 @@
file const** current_file;
};
- struct value_reset
- {
- typedef void result_type;
-
- value_reset(value_builder& b)
- : b(b) {}
-
- void operator()() const {
- b.reset();
- }
-
- value_builder& b;
- };
-
struct value_sort
{
typedef void result_type;
@@ -111,7 +97,6 @@
, save(builder)
, list(builder)
, entry(value_entry(builder, current_file))
- , reset(builder)
, sort(builder)
{}
@@ -121,7 +106,6 @@
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