|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r69188 - branches/quickbook-filenames/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-02-22 16:28:12
Author: danieljames
Date: 2011-02-22 16:28:07 EST (Tue, 22 Feb 2011)
New Revision: 69188
URL: http://svn.boost.org/trac/boost/changeset/69188
Log:
Handle elements in one rule.
Text files modified:
branches/quickbook-filenames/tools/quickbook/src/actions.cpp | 25 ++++
branches/quickbook-filenames/tools/quickbook/src/actions.hpp | 19 +++
branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp | 1
branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp | 3
branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp | 187 ++++++++++++++++++++-------------------
branches/quickbook-filenames/tools/quickbook/src/parsers.hpp | 32 ++++--
branches/quickbook-filenames/tools/quickbook/src/rule_store.hpp | 10 ++
branches/quickbook-filenames/tools/quickbook/src/scoped.hpp | 8 +
branches/quickbook-filenames/tools/quickbook/src/values_parse.hpp | 22 ++-
9 files changed, 190 insertions(+), 117 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 16:28:07 EST (Tue, 22 Feb 2011)
@@ -326,7 +326,7 @@
out << post;
}
- void cond_phrase_push::start()
+ bool cond_phrase_push::start()
{
saved_suppress = actions.suppress;
@@ -335,6 +335,8 @@
values.consume().get_quickbook().c_str());
actions.suppress = actions.suppress || !condition;
+
+ return true;
}
void cond_phrase_push::cleanup()
@@ -1717,11 +1719,13 @@
return (*this)(actions.out);
}
- void scoped_output_push::start()
+ bool scoped_output_push::start()
{
actions.out.push();
actions.phrase.push();
actions.anchors.swap(saved_anchors);
+
+ return true;
}
void scoped_output_push::cleanup()
@@ -1731,14 +1735,29 @@
actions.anchors.swap(saved_anchors);
}
- void set_no_eols_scoped::start()
+ bool set_no_eols_scoped::start()
{
saved_no_eols = actions.no_eols;
actions.no_eols = false;
+
+ return true;
}
void set_no_eols_scoped::cleanup()
{
actions.no_eols = saved_no_eols;
}
+
+ bool scoped_context_impl::start(int new_context)
+ {
+ saved_context_ = actions_.context;
+ actions_.context = new_context;
+
+ return true;
+ }
+
+ void scoped_context_impl::cleanup()
+ {
+ actions_.context = saved_context_;
+ }
}
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 16:28:07 EST (Tue, 22 Feb 2011)
@@ -162,7 +162,7 @@
cond_phrase_push(quickbook::actions& x)
: actions(x) {}
- void start();
+ bool start();
void cleanup();
quickbook::actions& actions;
@@ -443,7 +443,7 @@
scoped_output_push(quickbook::actions& actions)
: actions(actions) {}
- void start();
+ bool start();
void cleanup();
quickbook::actions& actions;
@@ -455,12 +455,25 @@
set_no_eols_scoped(quickbook::actions& actions)
: actions(actions) {}
- void start();
+ bool start();
void cleanup();
quickbook::actions& actions;
bool saved_no_eols;
};
+
+ struct scoped_context_impl : scoped_action_base
+ {
+ scoped_context_impl(quickbook::actions& actions)
+ : actions_(actions) {}
+
+ bool start(int);
+ void cleanup();
+
+ private:
+ quickbook::actions& actions_;
+ int saved_context_;
+ };
}
#ifdef BOOST_MSVC
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 16:28:07 EST (Tue, 22 Feb 2011)
@@ -42,6 +42,7 @@
, scoped_cond_phrase(*this)
, scoped_output(*this)
, scoped_no_eols(*this)
+ , scoped_context(*this)
// state
, filename(fs::absolute(filein_))
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 16:28:07 EST (Tue, 22 Feb 2011)
@@ -60,6 +60,8 @@
scoped_output;
scoped_parser<set_no_eols_scoped>
scoped_no_eols;
+ scoped_parser<scoped_context_impl>
+ scoped_context;
// state
fs::path filename;
@@ -95,6 +97,7 @@
bool no_eols;
bool suppress;
bool warned_about_breaks;
+ int context;
// push/pop the states and the streams
void copy_macros_for_write();
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 16:28:07 EST (Tue, 22 Feb 2011)
@@ -14,10 +14,9 @@
#include "template_tags.hpp"
#include "block_tags.hpp"
#include "parsers.hpp"
+#include "scoped.hpp"
#include <boost/spirit/include/classic_core.hpp>
-#include <boost/spirit/include/classic_confix.hpp>
#include <boost/spirit/include/classic_chset.hpp>
-#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>
@@ -82,24 +81,48 @@
main_grammar_local& l;
};
- struct check_element_type {
- check_element_type(main_grammar_local const& l, element_info::context t)
- : l(l), t(t) {}
+ 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))
+ return false;
+
+ // Save the element type because it might
+ // be overridden by nested markup.
+ element_type_ = l.element_type;
+
+ if (element_type_ & element_info::block)
+ l.actions_.paragraph();
+
+ l.actions_.values.reset()();
+
+ return true;
+ }
+
+ template <typename ResultT, typename ScannerT>
+ bool result(ResultT result, ScannerT const& scan)
+ {
+ if (result || !(l.element_type & element_info::block))
+ return result;
- bool operator()() const {
- return l.element_type & t;
+ l.actions_.error(scan.first, scan.first);
+ return true;
}
- main_grammar_local const& l;
- element_info::context t;
+ void success() { l.element_type = element_type_; }
+ void failure() { l.element_type = element_type_; }
+
+ main_grammar_local& l;
+ element_info::type_enum element_type_;
};
cl::rule<scanner>
top_level, blocks, paragraph_separator,
- block_element,
code, code_line, blank_line, hr,
- list, ordered_list, list_item,
- phrase_element, extended_phrase_element, element,
+ list, list_item, element,
simple_phrase_end,
escape,
inline_code, simple_format,
@@ -111,6 +134,7 @@
template_inner_arg_1_4, brackets_1_4,
template_args_1_5, template_arg_1_5, template_arg_1_5_content,
template_inner_arg_1_5, brackets_1_5,
+ break_,
command_line_macro_identifier, command_line_phrase,
dummy_block
;
@@ -118,21 +142,23 @@
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;
- main_grammar_local()
- : assign_element(*this) {}
-
- check_element_type check_element(element_info::context t) const {
- return check_element_type(*this, t);
- }
+ main_grammar_local(quickbook::actions& actions)
+ : actions_(actions)
+ , assign_element(*this)
+ , process_element(*this)
+ {}
};
void quickbook_grammar::impl::init_main()
{
using detail::var;
- main_grammar_local& local = store_.create();
+ main_grammar_local& local = store_.add(new main_grammar_local(actions));
block_skip_initial_spaces =
*(cl::blank_p | comment) >> block_start
@@ -142,15 +168,18 @@
local.top_level >> blank
;
- local.top_level
- = local.blocks
- >> *(
- local.block_element >> !(+eol >> local.blocks)
+ local.top_level =
+ actions.scoped_context(element_info::in_block)
+ [ local.blocks
+ >> *( local.element
+ >> !(+eol >> local.blocks)
| local.paragraph_separator >> local.blocks
| common
| cl::space_p [actions.space_char]
| cl::anychar_p [actions.plain_char]
- );
+ )
+ ]
+ ;
local.blocks =
*( local.code
@@ -172,20 +201,20 @@
>> +eol
;
- local.block_element
- = '[' >> space
- >> local.element
- >> cl::eps_p(local.check_element(element_info::in_block))
- [actions.paragraph]
- [actions.values.reset()]
- >> ( actions.values.list(detail::var(local.element_tag))
+ local.element
+ = '['
+ >> ( cl::eps_p(cl::punct_p)
+ >> elements [local.assign_element]
+ | elements [local.assign_element]
+ >> (cl::eps_p - (cl::alnum_p | '_'))
+ )
+ >> local.process_element()
+ [ actions.values.list(detail::var(local.element_tag))
[ local.element_rule
- >> ( (space >> ']')
- | cl::eps_p [actions.error]
- )
+ >> space
+ >> ']'
] [actions.element]
- | cl::eps_p [actions.error]
- )
+ ]
;
local.code =
@@ -233,13 +262,17 @@
;
common =
- local.macro
- | local.phrase_element
+ actions.scoped_context(element_info::in_phrase)
+ [ local.macro
+ | local.element
+ | local.template_
+ | local.break_
| local.code_block
| local.inline_code
| local.simple_format
| local.escape
| comment
+ ]
;
local.macro =
@@ -250,7 +283,8 @@
;
local.template_ =
- cl::eps_p [actions.values.reset()]
+ ( '['
+ >> space [actions.values.reset()]
>> !cl::str_p("`") [actions.values.entry(ph::arg1, ph::arg2, template_tags::escape)]
>>
( (
@@ -265,8 +299,8 @@
>> space
>> !local.template_args
) )
- >> cl::eps_p(']')
- >> cl::eps_p [actions.do_template]
+ >> ']'
+ ) [actions.do_template]
;
local.template_args =
@@ -315,6 +349,15 @@
'[' >> local.template_inner_arg_1_5 >> ']'
;
+ local.break_
+ = ( '['
+ >> space
+ >> "br"
+ >> space
+ >> ']'
+ ) [actions.break_]
+ ;
+
local.inline_code =
'`' >>
(
@@ -365,18 +408,23 @@
simple_markup(local.simple_teletype,
'=', actions.simple_teletype, local.simple_phrase_end);
- phrase = actions.values.save()[
- *( common
- | (cl::anychar_p - phrase_end) [actions.plain_char]
- )
+ phrase =
+ actions.values.save()
+ [ *( common
+ | (cl::anychar_p - phrase_end)
+ [actions.plain_char]
+ )
]
;
- extended_phrase = actions.values.save()[
- *( local.extended_phrase_element
- | common
- | (cl::anychar_p - phrase_end) [actions.plain_char]
- )
+ extended_phrase =
+ actions.values.save()
+ [ *( actions.scoped_context(element_info::in_conditional)
+ [ local.element ]
+ | common
+ | (cl::anychar_p - phrase_end)
+ [actions.plain_char]
+ )
]
;
@@ -390,45 +438,6 @@
] [actions.paragraph]
;
- local.phrase_element
- = '['
- >> space
- >> ( local.element
- >> cl::eps_p(local.check_element(element_info::in_phrase))
- [actions.values.reset()]
- >> actions.values.list(detail::var(local.element_tag))
- [ local.element_rule
- >> cl::eps_p(space >> ']')
- ] [actions.element]
- | local.template_
- | cl::str_p("br") [actions.break_]
- )
- >> ']'
- ;
-
- local.extended_phrase_element
- = '[' >> space
- >> local.element
- >> cl::eps_p(local.check_element(element_info::in_conditional))
- [actions.paragraph]
- [actions.values.reset()]
- >> ( actions.values.list(detail::var(local.element_tag))
- [ local.element_rule
- >> ( (space >> ']')
- | cl::eps_p [actions.error]
- )
- ] [actions.element]
- | cl::eps_p [actions.error]
- )
- ;
-
- local.element
- = cl::eps_p(cl::punct_p)
- >> elements [local.assign_element]
- | elements [local.assign_element]
- >> (cl::eps_p - (cl::alnum_p | '_'))
- ;
-
local.escape =
cl::str_p("\\n") [actions.break_]
| cl::str_p("\\ ") // ignore an escaped space
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 16:28:07 EST (Tue, 22 Feb 2011)
@@ -65,24 +65,24 @@
typedef phoenix::tuple_index<0> t0;
typedef phoenix::tuple_index<1> t1;
- void start(phoenix::tuple<> const&)
+ bool start(phoenix::tuple<> const&)
{
- impl_.start();
- in_progress_ = true;
+ in_progress_ = impl_.start();
+ return in_progress_;
}
template <typename Arg1>
- void start(phoenix::tuple<Arg1> const& x)
+ bool start(phoenix::tuple<Arg1> const& x)
{
- impl_.start(x[t0()]);
- in_progress_ = true;
+ in_progress_ = impl_.start(x[t0()]);
+ return in_progress_;
}
template <typename Arg1, typename Arg2>
- void start(phoenix::tuple<Arg1, Arg2> const& x)
+ bool start(phoenix::tuple<Arg1, Arg2> const& x)
{
- impl_.start(x[t0()], x[t1()]);
- in_progress_ = true;
+ in_progress_ = impl_.start(x[t0()], x[t1()]);
+ return in_progress_;
}
void success()
@@ -114,16 +114,22 @@
iterator_t save = scan.first;
scoped scope(impl_);
- scope.start(arguments_);
+ if (!scope.start(arguments_))
+ return scan.no_match();
typename cl::parser_result<ParserT, ScannerT>::type result
= this->subject().parse(scan);
- //result = scope.match(result);
+ bool success = scope.impl_.result(result, scan);
- if (result) {
+ if (success) {
scope.success();
- return scan.create_match(result.length(), cl::nil_t(), save, scan.first);
+ if (result) {
+ return scan.create_match(result.length(), cl::nil_t(), save, scan.first);
+ }
+ else {
+ return scan.create_match(scan.first.base() - save.base(), cl::nil_t(), save, scan.first);
+ }
}
else {
scope.failure();
Modified: branches/quickbook-filenames/tools/quickbook/src/rule_store.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/rule_store.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/rule_store.hpp 2011-02-22 16:28:07 EST (Tue, 22 Feb 2011)
@@ -72,6 +72,16 @@
instantiate i(*this);
return i;
}
+
+ template <typename T>
+ T& add(T* new_)
+ {
+ std::auto_ptr<T> obj(new_);
+ store_.push_back(detail::scoped_void());
+ store_.back().store(obj.release(), &detail::delete_impl<T>);
+
+ return *new_;
+ }
std::deque<detail::scoped_void> store_;
private:
Modified: branches/quickbook-filenames/tools/quickbook/src/scoped.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/scoped.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/scoped.hpp 2011-02-22 16:28:07 EST (Tue, 22 Feb 2011)
@@ -15,10 +15,16 @@
struct scoped_action_base
{
- void start() {}
+ bool start() { return true; }
void success() {}
void failure() {}
void cleanup() {}
+
+ template <typename ResultT, typename ScannerT>
+ bool result(ResultT result, ScannerT const&)
+ {
+ return result;
+ }
};
}
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 16:28:07 EST (Tue, 22 Feb 2011)
@@ -11,6 +11,7 @@
#include "values.hpp"
#include "parsers.hpp"
+#include "scoped.hpp"
#include <boost/spirit/include/phoenix1_functions.hpp>
#include <iostream>
@@ -18,28 +19,33 @@
namespace quickbook {
namespace ph = phoenix;
- struct value_builder_save
+ struct value_builder_save : scoped_action_base
{
value_builder_save(value_builder& builder) : builder(builder) {}
- void start() { builder.save(); }
- void success() {}
- void failure() {}
+ bool start()
+ {
+ builder.save();
+ return true;
+ }
+
void cleanup() { builder.restore(); }
value_builder& builder;
};
- struct value_builder_list
+ struct value_builder_list : scoped_action_base
{
value_builder_list(value_builder& builder) : builder(builder) {}
- void start(value::tag_type tag = value::default_tag)
- { builder.start_list(tag); }
+ bool start(value::tag_type tag = value::default_tag)
+ {
+ builder.start_list(tag);
+ return true;
+ }
void success() { builder.finish_list(); }
void failure() { builder.clear_list(); }
- void cleanup() {}
value_builder& builder;
};
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