|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r70196 - in trunk/tools/quickbook: . src test
From: dnljms_at_[hidden]
Date: 2011-03-19 12:28:52
Author: danieljames
Date: 2011-03-19 12:28:49 EDT (Sat, 19 Mar 2011)
New Revision: 70196
URL: http://svn.boost.org/trac/boost/changeset/70196
Log:
Quickbook: further improvements for simple markup.
Added:
trunk/tools/quickbook/test/fail-mismatched-boostbook-escape.quickbook
- copied unchanged from r69310, /branches/quickbook-filenames/tools/quickbook/test/fail-mismatched-boostbook-escape.quickbook
Properties modified:
trunk/tools/quickbook/ (props changed)
Text files modified:
trunk/tools/quickbook/src/actions.cpp | 24 ++++++-
trunk/tools/quickbook/src/actions.hpp | 6 --
trunk/tools/quickbook/src/actions_class.cpp | 6 -
trunk/tools/quickbook/src/actions_class.hpp | 6 -
trunk/tools/quickbook/src/main_grammar.cpp | 114 +++++++++++++++++----------------------
trunk/tools/quickbook/test/Jamfile.v2 | 1
trunk/tools/quickbook/test/simple_markup.gold | 5 +
trunk/tools/quickbook/test/simple_markup.quickbook | 5 +
8 files changed, 80 insertions(+), 87 deletions(-)
Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp (original)
+++ trunk/tools/quickbook/src/actions.cpp 2011-03-19 12:28:49 EDT (Sat, 19 Mar 2011)
@@ -17,6 +17,7 @@
#include <boost/lexical_cast.hpp>
#include <boost/range/distance.hpp>
#include <boost/algorithm/string/replace.hpp>
+#include <boost/next_prior.hpp>
#include "quickbook.hpp"
#include "actions.hpp"
#include "utils.hpp"
@@ -311,18 +312,31 @@
{
if(!actions.output_pre(out)) return;
- out << pre;
- std::string str(first, last);
+ char mark = *first;
+ int tag =
+ mark == '*' ? phrase_tags::bold :
+ mark == '/' ? phrase_tags::italic :
+ mark == '_' ? phrase_tags::underline :
+ mark == '=' ? phrase_tags::teletype :
+ 0;
+
+ assert(tag != 0);
+ detail::markup markup = detail::markups[tag];
+
+ std::string str(
+ boost::next(first.base()),
+ boost::prior(last.base()));
+
+ out << markup.pre;
if (std::string const* ptr = find(macro, str.c_str()))
{
out << *ptr;
}
else
{
- while (first != last)
- detail::print_char(*first++, out.get());
+ detail::print_string(str, out.get());
}
- out << post;
+ out << markup.post;
}
bool cond_phrase_push::start()
Modified: trunk/tools/quickbook/src/actions.hpp
==============================================================================
--- trunk/tools/quickbook/src/actions.hpp (original)
+++ trunk/tools/quickbook/src/actions.hpp 2011-03-19 12:28:49 EDT (Sat, 19 Mar 2011)
@@ -136,21 +136,15 @@
simple_phrase_action(
collector& out
- , std::string const& pre
- , std::string const& post
, string_symbols const& macro
, quickbook::actions& actions)
: out(out)
- , pre(pre)
- , post(post)
, macro(macro)
, actions(actions) {}
void operator()(iterator first, iterator last) const;
collector& out;
- std::string pre;
- std::string post;
string_symbols const& macro;
quickbook::actions& actions;
};
Modified: trunk/tools/quickbook/src/actions_class.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions_class.cpp (original)
+++ trunk/tools/quickbook/src/actions_class.cpp 2011-03-19 12:28:49 EDT (Sat, 19 Mar 2011)
@@ -77,11 +77,7 @@
, raw_char(phrase, *this)
, escape_unicode(phrase, *this)
- , simple_bold(phrase, bold_pre_, bold_post_, macro, *this)
- , simple_italic(phrase, italic_pre_, italic_post_, macro, *this)
- , simple_underline(phrase, underline_pre_, underline_post_, macro, *this)
- , simple_teletype(phrase, teletype_pre_, teletype_post_, macro, *this)
- , simple_strikethrough(phrase, strikethrough_pre_, strikethrough_post_, macro, *this)
+ , simple_markup(phrase, macro, *this)
, break_(phrase, *this)
, do_macro(phrase, *this)
Modified: trunk/tools/quickbook/src/actions_class.hpp
==============================================================================
--- trunk/tools/quickbook/src/actions_class.hpp (original)
+++ trunk/tools/quickbook/src/actions_class.hpp 2011-03-19 12:28:49 EDT (Sat, 19 Mar 2011)
@@ -122,11 +122,7 @@
raw_char_action raw_char;
escape_unicode_action escape_unicode;
- simple_phrase_action simple_bold;
- simple_phrase_action simple_italic;
- simple_phrase_action simple_underline;
- simple_phrase_action simple_teletype;
- simple_phrase_action simple_strikethrough;
+ simple_phrase_action simple_markup;
break_action break_;
do_macro_action do_macro;
Modified: trunk/tools/quickbook/src/main_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/main_grammar.cpp (original)
+++ trunk/tools/quickbook/src/main_grammar.cpp 2011-03-19 12:28:49 EDT (Sat, 19 Mar 2011)
@@ -19,6 +19,7 @@
#include <boost/spirit/include/classic_chset.hpp>
#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/phoenix1_primitives.hpp>
#include <boost/spirit/include/phoenix1_casts.hpp>
@@ -26,47 +27,6 @@
{
namespace cl = boost::spirit::classic;
- template <typename Rule, typename Action>
- inline void
- simple_markup(
- Rule& simple
- , char mark
- , Action const& action
- , Rule const& close
- )
- {
- simple =
- mark
- >> lookback
- [ cl::anychar_p
- >> ~cl::eps_p(mark) // first mark not be preceeded by
- // the same character.
- >> (cl::space_p | cl::punct_p | cl::end_p)
- // first mark must be preceeded
- // by space or punctuation or the
- // mark character or a the start.
- ]
- >> ( cl::graph_p // graph_p must follow first mark
- >> *( cl::anychar_p -
- ( lookback[cl::graph_p]
- // final mark must be preceeded by
- // graph_p
- >> mark
- >> ~cl::eps_p(mark) // final mark not be followed by
- // the same character.
- >> (cl::space_p | cl::punct_p | cl::end_p)
- // final mark must be followed by
- // space or punctuation
- | close // Make sure that we don't go
- // past a single block
- )
- )
- >> cl::eps_p(mark)
- ) [action]
- >> mark
- ;
- }
-
struct main_grammar_local
{
struct assign_element_type {
@@ -141,11 +101,9 @@
top_level, blocks, paragraph_separator,
code, code_line, blank_line, hr,
list, list_item, element,
- simple_phrase_end,
escape,
- inline_code, simple_format,
- simple_bold, simple_italic, simple_underline,
- simple_teletype, template_,
+ inline_code,
+ template_,
code_block, macro,
template_args,
template_args_1_4, template_arg_1_4,
@@ -157,6 +115,15 @@
dummy_block
;
+ struct simple_markup_closure
+ : cl::closure<simple_markup_closure, char>
+ {
+ member1 mark;
+ };
+
+ cl::rule<scanner, simple_markup_closure::context_t>
+ simple_markup, simple_markup_end;
+
element_info::type_enum element_type;
cl::rule<scanner> element_rule;
value::tag_type element_tag;
@@ -293,7 +260,7 @@
| local.break_
| local.code_block
| local.inline_code
- | local.simple_format
+ | local.simple_markup
| local.escape
| comment
;
@@ -413,23 +380,40 @@
)
;
- local.simple_format =
- local.simple_bold
- | local.simple_italic
- | local.simple_underline
- | local.simple_teletype
- ;
-
- local.simple_phrase_end = '[' | phrase_end;
-
- simple_markup(local.simple_bold,
- '*', actions.simple_bold, local.simple_phrase_end);
- simple_markup(local.simple_italic,
- '/', actions.simple_italic, local.simple_phrase_end);
- simple_markup(local.simple_underline,
- '_', actions.simple_underline, local.simple_phrase_end);
- simple_markup(local.simple_teletype,
- '=', actions.simple_teletype, local.simple_phrase_end);
+ local.simple_markup =
+ ( cl::chset<>("*/_=") [local.simple_markup.mark = ph::arg1]
+ >> lookback
+ [ cl::anychar_p
+ >> ~cl::eps_p(cl::f_ch_p(local.simple_markup.mark))
+ // first mark not be preceeded by
+ // the same character.
+ >> (cl::space_p | cl::punct_p | cl::end_p)
+ // first mark must be preceeded
+ // by space or punctuation or the
+ // mark character or a the start.
+ ]
+ >> cl::graph_p // graph_p must follow first mark
+ >> *(cl::anychar_p - local.simple_markup_end(local.simple_markup.mark))
+ >> cl::f_ch_p(local.simple_markup.mark)
+ ) [actions.simple_markup]
+ ;
+
+ local.simple_markup_end
+ = ( lookback[cl::graph_p] // final mark must be preceeded by
+ // graph_p
+ >> cl::f_ch_p(local.simple_markup_end.mark)
+ >> ~cl::eps_p(cl::f_ch_p(local.simple_markup_end.mark))
+ // final mark not be followed by
+ // the same character.
+ >> (cl::space_p | cl::punct_p | cl::end_p)
+ // final mark must be followed by
+ // space or punctuation
+ )
+ | '['
+ | "'''"
+ | '`'
+ | phrase_end
+ ;
phrase =
actions.scoped_context(element_info::in_phrase)
@@ -479,7 +463,9 @@
| (
("'''" >> !eol) [actions.escape_pre]
>> *(cl::anychar_p - "'''") [actions.raw_char]
- >> cl::str_p("'''") [actions.escape_post]
+ >> ( cl::str_p("'''") [actions.escape_post]
+ | cl::eps_p [actions.error("Unclosed boostbook escape.")]
+ )
)
;
Modified: trunk/tools/quickbook/test/Jamfile.v2
==============================================================================
--- trunk/tools/quickbook/test/Jamfile.v2 (original)
+++ trunk/tools/quickbook/test/Jamfile.v2 2011-03-19 12:28:49 EDT (Sat, 19 Mar 2011)
@@ -78,6 +78,7 @@
[ quickbook-error-test fail-unknown-quickbook-1 ]
[ quickbook-error-test fail-unknown-quickbook-2 ]
[ quickbook-error-test fail-unknown-quickbook-3 ]
+ [ quickbook-error-test fail-mismatched-boostbook-escape ]
[ quickbook-test utf-8 ]
[ quickbook-test utf-8-bom ]
[ quickbook-test unicode-escape ]
Modified: trunk/tools/quickbook/test/simple_markup.gold
==============================================================================
--- trunk/tools/quickbook/test/simple_markup.gold (original)
+++ trunk/tools/quickbook/test/simple_markup.gold 2011-03-19 12:28:49 EDT (Sat, 19 Mar 2011)
@@ -17,7 +17,7 @@
not__underlined__hopefully
</para>
<para>
- (<emphasis role="bold">bold</emphasis>)
+ (<emphasis role="bold">bold</emphasis>) <emphasis role="underline">und/er/lined</emphasis>
</para>
<para>
<emphasis>all/italic</emphasis> * not bold*
@@ -28,5 +28,8 @@
<para>
not_underlined_
</para>
+ <para>
+ _Should not underline escaped markup_. _or this escaped_ markup form.
+ </para>
</section>
</article>
Modified: trunk/tools/quickbook/test/simple_markup.quickbook
==============================================================================
--- trunk/tools/quickbook/test/simple_markup.quickbook (original)
+++ trunk/tools/quickbook/test/simple_markup.quickbook 2011-03-19 12:28:49 EDT (Sat, 19 Mar 2011)
@@ -10,7 +10,7 @@
not__underlined__hopefully
-(*bold*)
+(*bold*) _und/er/lined_
/all/italic/ * not bold*
@@ -18,4 +18,7 @@
not_underlined_
+_Should not underline '''escaped''' markup_.
+_or this '''escaped_ markup''' form.
+
[endsect]
\ No newline at end of file
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